Hi Mike!
I'm having a bit of trouble using the upsert. I have pretty much stripped much of your code because I'm not migrating data from one database to another. Instead I'll be inputting information from a form into SalesForce, but to make things simple I've provided the following code and the warning message. This is exactly what I'm using...
PHP Code:
ini_set("soap.wsdl_cache_enabled", "0");
require_once ('soapclient/SforcePartnerClient.php');
require_once ('soapclient/SforceHeaderOptions.php');
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection("soapclient/partner.wsdl.xml");
$mylogin = $mySforceConnection->login("XXX@XXX.XXX", "XXXX");
$Array=array();
$Array[0]['FirstName']='TEST123';
$sObjects = array();
foreach($Array as $fieldset)
{
$sObject = new sObject();
$sObject->type = 'Lead'; //SalesForce field or object you'll be working with
$sObject->fields = $fieldset;
array_push($sObjects, $sObject);
}
$results = $mySoapClient->upsert("ExternalIdField__c", $sObjects);
$k=0;
foreach ($results as $result)
{
// Build string from fields in $sObjects array
// At this point, the record has already been upserted
// We just need the data for the log file
// The string is the same, regardless of the result
$data2 = $sObjects[$k]->fields['NAME'] . ", " . $sObjects[$k]->fields['SA_ID__C'];
if ($result->success)
{
if ($result->created)
{
$accounts_created++;
#file_put_contents($file_created, $data2 . "\n", FILE_APPEND);
echo $data."<br />";
}
else
{
$accounts_updated++;
file_put_contents($file_updated, $data2 . "\n", FILE_APPEND);
echo $data."<br />";
}
}
else
{
$accounts_failed++;
// The errors object also contains fields and status_code
$errMessage = $result->errors->message;
#file_put_contents($file_failed, $data2 . ", " . $errMessage . "\n", FILE_APPEND);
echo $errMessage."<br />";
}
$k++;
}
And this is the error I'm getting.
Uncaught SoapFault exception: [sf:INVALID_SESSION_ID] INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session in D:\xampp\htdocs\classes\salesforcephp\index.php:23 5 Stack trace: #0 [internal function]: SoapClient->__call('upsert', Array) #1 D:\xampp\htdocs\classes\salesforcephp\index.php(23 5): SoapClient->upsert('ExternalIdField...', Array) #2 {main} thrown in D:\xampp\htdocs\classes\salesforcephp\index.php on line 235
As you can see I've stripped allot of it and echoed the results instead while only inserting 1 record in the FirstName. I've created the external field Id which is basically a text value that does not need to be unique with no default value. Is there anything I'm missing? The error is on the actual query call:
PHP Code:
$results = $mySoapClient->upsert("ExternalIdField__c", $sObjects);
Bookmarks