You need to sign in to do that
Don't have an account?
Upserting Custom Objects with Enterprise Client
I'm not sure who is maintaining the PHP Toolkit code, but I keep coming across things that don't seem to make any sense (and they seem easily fixable). For example, I just downloaded PHP Toolkit 13.1 and tried to upsert a record into a custom object.
Of course, there's no sample code for the upsert method for the Enterprise client - only the Partner client and that sample doesn't work at all. Inside SforceEnterpriseClient.php's upsert method, "Contact" is literally hardcoded as the object type.
I changed the code from:
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);
}
to:
public function upsert($ext_Id, $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);
}
That seems to solve the problem - I simply pass the custom object's name as the third argument, and the field list array as the second argument, and it works just fine. Why can't SalesForce just make that the default behavior? It's been hardcoded for years now... (and nobody's ever bothered to fill out the rest of the PHP Toolkit documentation)
The following is a better fix to the above as it changes the function to act more like the apex api
This changes the order of the prams to move the optional prams to the end of the call.
This change is to better take advantage of Defaulting values in PHP.