Sample Call
<?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.com password
// note: there is a bug in the SforceEnterpriseClient upsert method
// so this code may work for the SforcePartnerClient,
// but it doesn't work for SforceEnterpriseClient
// the SforceEnterpriseClient upsert method has the sObject type
// mis-hardcoded to 'Contact'
// wish someone at sf.com would fix SforceEnterpriseClient...
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once ('../userAuth.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);
}
?>
Sample Output
// Returns object
// Created will be "true" if the object didn't exist.
object(stdClass)#12 (3) {
["created"]=>
bool(false)
["id"]=>
string(18) "AQ0239JFA2309JZOI"
["success"]=>
bool(true)
}