
The Upsert method takes two arguments:
external id (string)
array (array of SObjects)
<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.ocm password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$createFields = array (
'FirstName' => 'George',
'LastName' => 'Smith',
'Phone' => '510-555-5555',
'BirthDate' => '1927-01-25',
'customfield__c' => 'President 40b'
);
$sObject = new stdclass();
$sObject->fields = $createFields;
$sObject->type = 'Contact';
echo "Creating New Contact\n";
$createResponse = $mySforceConnection->create(array($sObject));
print_r($createResponse);
$sObject->fields['FirstName'] = 'Bill';
$sObject->fields['LastName'] = 'Clinton';
$sObject->fields['customfield__c'] = 'President 40b';
echo "Upserting Contact (existing)\n";
$upsertResponse = $mySforceConnection->upsert("customfield__c", array ($sObject));
print_r($upsertResponse);
$sObject->fields['FirstName'] = 'John';
$sObject->fields['LastName'] = 'Smith';
$sObject->fields['customfield__c'] = 'President 99a';
echo "Upserting Contact (new)\n";
$upsertResponse = $mySforceConnection->upsert("customfield__c", array ($sObject));
print_r($upsertResponse);
} catch (Exception $ex) {
print_r($ex);
echo $mySforceConnection->getLastRequest();
print_r($ex);
}
?>