/** * Creates new objects and updates existing objects; uses a custom field to * determine the presence of existing objects. In most cases, we recommend * that you use upsert instead of create because upsert is idempotent. * Available in the API version 7.0 and later. * * @param string $ext_Id External Id * @param array $sObjects Array of sObjects * @param string $type The type of objects being upserted. * @return UpsertResult */ public function upsert($ext_Id, $sObjects, $type = 'Contact') { $arg = new stdClass(); $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); foreach ($sObjects as &$sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if (isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { foreach ($sObject->fieldsToNull as $fieldToNull) { $xmlStr .= '<fieldsToNull>' . $fieldToNull . '</fieldsToNull>'; } } // ------ $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if ($xmlStr != '') { $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } // ------ } $arg->sObjects = $sObjects; return parent::_upsert($arg); }
/** * Creates new objects and updates existing objects; uses a custom field to * determine the presence of existing objects. In most cases, we recommend * that you use upsert instead of create because upsert is idempotent. * Available in the API version 7.0 and later. * * @param string $ext_Id External Id * @param array $sObjects Array of sObjects * @return UpsertResult */ public function upsert($ext_Id, $sObjects) { // $this->_setSessionHeader(); $arg = new \stdClass(); $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); foreach ($sObjects as $sObject) { if (isset($sObject->fields)) { $sObject->any = $this->_convertToAny($sObject->fields); } } $arg->sObjects = $sObjects; return parent::_upsert($arg); }