function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sf_davesf_dave 

upsert always tries to create a Contact

I have finished integrating the Salesforce API into our web app and have started testing the capabilities of upsert.  I created a simple mapping from our Accounts to a Salesforce Account SObject and tried to upsert it with the correct External ID I specified on our account form.

it wasn't adding the account so I traced out what variables the API was trying to access in the __get method of my mapping.  It turns out the API was always asking for the fields in the Contact Object!!

I looked at the code for upsert in the SforceEnterpriseClient.php from the 1.1.1 SDK and found this:
Code:
  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) {
      $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, 'Contact', "urn:sobject.enterprise.soap.sforce.com");
    }
    $arg->sObjects = $sObjects;
    return $this->sforce->upsert($arg)->result;
  }

 
Note the line:
$sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, 'Contact', ....

Why is the Contact object hard coded in the upsert call?  I thought it determined what object it was base don the External ID pased to the API?? In my case this is CompanyId__c

Is there something explicitly wrong going on here?

Thanks
-Dave


Message Edited by sf_dave on 01-02-2008 09:54 PM
msimondsmsimonds
Dave,

Get a newer version of the php toolkit or change the method in the SforceBaseClient.php to this:

Code:
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 $this->sforce->upsert($arg)->result;
    }

 
Hope this helps

~Mike
sf_davesf_dave
Thanks for your reply Mike!

I'll try out your code shortly.  I just wanted to point out that the 1.1.1 SDK that is posted on salesforce.com/developer still have the code I posted.  I re-downloaded it late last night and diff'd it against what I have and the files are the same.

Thanks again for your help Mike, I'll report back my progress.

Thanks
-Dave
sf_davesf_dave
Mike,

I just wanted to report that I checked my code in the SforceBaseClient.php and my upsert method is the same.  Do I need to explicitly call the base upsert instead of the derived one (i.e. comment out the on in the Enterprise Client)? 

Should I modify the Enterprise client to change the object listed in that line based on my external ID's?

Any help on how to proceed is appreciated.  This is becoming a time sensitive matter.

Thanks
-Dave
msimondsmsimonds
Dave

I always use the SforcePartnerClient.php, try that one!!!
sf_davesf_dave
Thanks for the heads up Mike,

I'm looking to switch our API to the partner one, but as Enterprise customers, it would make sense to be able to use the "Enterprise" API Client.

The differences between seem to be that the Enterprise client overrides update, upsert, merge, processSubmitRequest, ProcessWorkItemRequest and create.

while the Partner client defines an SObject, a QueryResult, along with the constructor for the PartnerClient().

Is there an official salesforce place I can direct questions like this?

Thanks
-Dave


Message Edited by sf_dave on 01-03-2008 02:01 PM
msimondsmsimonds
Nope Dave this is the official site!  Maybe you'll get lucky and an admin will respond to your question
sf_davesf_dave
Any recomendations on how to get an admin to this thread?? ;)

Thanks again Mike!