Explainations

First of all check your class SforceEnterpriseClient.php if you have something like:

<?php
  public function upsert($ext_Id, $sObjects) {
    $arg = new stdClass;
    $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    foreach ($sObjects as &$sObject) {
      $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, 'Contact', $this->namespace);
    }
    $arg->sObjects = $sObjects;
    return parent::_upsert($arg);
  }
?>

go and throw up and change it to

<?php
  public function upsert($ext_Id, array $sObjects, $objectType = 'Contact') {
    $arg = new stdClass;
    $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    foreach ($sObjects as &$sObject) {
      $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $objectType, $this->namespace);
    }
    $arg->sObjects = $sObjects;
    return parent::_upsert($arg);
  }
?>
  • $ext_Id is the Id you want to trigger the upsert on. It should by unique so anything but the Salesforce Id could be madness unless you really know what you are doing. (IMHO It should be an optional Parameter and default should be the Salesforce Id)
  • $sObjects is an array of Objects of type stdClass (NB only Enterprise)
  • $objectType is the Table where you want to upsert the data it can be Contact but also YOUR_OBJECT__c will work fine.

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

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('../userAuth.php');
try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $sObject = new stdClass();
  $sObject->FirstName = 'George';
  $sObject->LastName = 'Smith';
  $sObject->Phone = '510-555-5555';
  $sObject->BirthDate = '1927-01-25';
  $sObject->Email = 'test@test.com';
		
  $createResponse = $this->_mySforceConnection->create(array($sObject), $objectType);
  echo "Creating New Contact\r\n";
  print_r($createResponse);
		
  $sObject->FirstName = 'Bill';
  $sObject->LastName = 'Clinton';
		
  $upsertResponse = $this->_mySforceConnection->upsert('Email', array ($sObject), $objectType);
  echo "Upserting Contact (existing)\r\n";
  print_r($upsertResponse);
		
  $sObject->FirstName = 'John';
  $sObject->LastName = 'Smith';
  $sObject->Email = 'testNew@test.com';
		
  echo "Upserting Contact (new)\n";
  $upsertResponse = $this->_mySforceConnection->upsert('Email', array ($sObject), $objectType);
  print_r($upsertResponse);
} catch (Exception $e) {
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}
?>

Sample Output

Creating New Contact
stdClass Object
(
    [id] => 0035000000o1afRAAQ
    [success] => 1
)
Upserting Contact (existing)
stdClass Object
(
    [created] => 
    [id] => 0035000000o1afRAAQ
    [success] => 1
)
Upserting Contact (new)
stdClass Object
(
    [created] => 1
    [id] => 0035000000o1aeUAAQ
    [success] => 1
)