Adding a wordpress user to Salesforce Contact

I'm trying to do a relatively simple task by hooking into the Wordpress registration and adding the user that's being registered to a Salesforce db. When I run the Salesforce db code outside of Wordpress it works flawlessly, but when I test this by registering on my wordpress website, I get an error stating: INVALID_LOGIN: Invalid username, password, security token; or user locked out.

Additionally, I receive this error from Wordpress "Cannot modify header information - headers already sent" which doesn't allow me to view the entire object data that's being sent to Salesforce.

This is my code:

 $SF_USERNAME = 'test';
 $SF_PASSWORD = 'test';

 define( 'CD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );

 require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceEnterpriseClient.php');
 require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceHeaderOptions.php');


 function add_user_to_SF($user_id) {
$user = get_userdata($user_id);

 try {
     $mySforceConnection = new SforceEnterpriseClient();
     $mySoapClient = $mySforceConnection->createConnection(CD_PLUGIN_PATH . 'Toolkit/soapclient/enterprise.wsdl.xml');
     $mylogin = $mySforceConnection->login($SF_USERNAME, $SF_PASSWORD);

     print '<pre>'; 
     print_r($mylogin);
     print '</pre>';
     print '<br/><br/>';

$sObject = new stdclass();
$sObject->FirstName = $user->first_name;
$sObject->LastName = $user->last_name;
$sObject->Email = $user->user_email;

//echo "**** Creating the following:\r\n";
$createResponse = $mySforceConnection->create(array($sObject), 'Contact');

$ids = array();
    foreach ($createResponse as $createResult) {
        print_r($createResult);
        array_push($ids, $createResult->id);
    }

    } catch (Exception $e) {
      $errors->add( 'demo_error', __(print_r($_POST),'mydomain') );
      $errors->add( 'demo_error', __($mySforceConnection->getLastRequest(),'mydomain') );
      $errors->add( 'demo_error', __($e->faultstring,'mydomain') );
      return $errors;
}

}

 add_filter( 'registration_errors', 'add_user_to_SF', 10, 3 );

Answers


This is a php scope issue.

Adding: global $SF_USERNAME; global $SF_PASSWORD;

inside the function fixed the problem.


It looks like you might be missing the security token. It's appended to the end of the password.

This link explains how to generate the token

https://login.salesforce.com/help/doc/en/user_security_token.htm


You need to add your salesforce account security token with password eg. Password - "testing" Security Token - "2321njjn32j32" You need to pass as - "testing2321njjn32j32"

This will work properly.


Need Your Help

Deserialize json array stream one item at a time

c# json serialization stream json.net

I serialize an array of large objects to a json http response stream. Now I want to deserialize these objects from the stream one at a time. Are there any c# libraries that will let me do this? I've

removeRows() and QPersistentModelIndex

c++ qt model qabstractitemmodel qabstractlistmodel

I have implemented my own QAbstractListModel which is based on an std::vector. I now want to display the contents of this model in a QGraphicsScene. For this I have implemented my own QGraphicsItem...