Garside over at the Salesforce forums was having an issue with creating a new user and was getting an error:
Code:
INVALID_CROSS_REFERENCE_KEY
I copied his code and added it to a small script that I have:
PHP Code:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
require_once ('./includes/soapclient/SforcePartnerClient.php');
require_once ('./includes/soapclient/SforceHeaderOptions.php');
$mystuff = array('Username' => 'user@email.com', // change this to a valid email
'LastName' => 'Wiley',
'FirstName' => 'Mike',
'Email' => 'user@email.com', // change this to a valid email
'Alias' => 'MWile',
'IsActive' => 'true',
'TimeZoneSidKey' => 'America/New_York',
'LocaleSidKey' => 'en_US',
'EmailEncodingKey' => 'ISO-8859-1',
'ProfileId' => '00e50000000r9vdAAA',
'LanguageLocaleKey'=> 'en_US');
//clean User to allow changing of characters to XML
$mystuff = array_map('htmlspecialchars', $mystuff);
//try to add User from from array
try
{
//salesforce login and wsdl
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "user@email.com"; // change this to a valid email
$password = "password"; // change this to a valid password
//connect to salesforce
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
$sObject = new sObject();
$sObject->type = 'User';
$sObject->fields = $mystuff;
//this part adds the contact to salesforce
$result = $client->create(array($sObject));
if ($result->success)
{
echo "New User has been added to your instance of Salesforce with an Id of " . $result->id . "<br />";
echo "**************** ALL DONE ****************<br />";
exit;
}
else
{
$errMessage = $result->errors->message;
echo $errMessage;
}
}
catch (exception $e)
{
// This is reached if there is a major problem in the data or with
// the salesforce.com connection. Normal data errors are caught by
// salesforce.com
echo '<pre>' . print_r($e, true) . '</pre>';
return false;
exit;
}
?>
just make sure you change the emails in the user to someone valid and your salesforce login and password
This script worked for me
let me know if it doesn't for you
~Mike
Bookmarks