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
Sean FieldingSean Fielding 

Unable to get foreign key to work with partner wsdl and upsert

$sObject = new sObject();
$sObject->type = 'Object1__c';

 

       $sObject->fields['Data1__c'] = $data[1];
       $sObject->fields['ExternalId__c'] = $data[2];

       $sObjects[] = $sObject;
       $status = upsert($mySforceConnection,$sObjects);

 

This works correctly.  I then try to introduce a foreign key and everything fails.

 

 

$sObject = new sObject();
$sObject->type = 'Object1__c';

 

       $sObject->fields['Data1__c'] = $data[1];
       $sObject->fields['ExternalId__c'] = $data[2];

 

       $key = new sObject();
       $key->type = 'Subscription__c';
       $key->fields['buying_email_address__c'] = $data[0];
       $sObject->fields['Subscription__r'] = $key;

 

   $sObjects[] = $sObject;
       $status = upsert($mySforceConnection,$sObjects);

 

The field subscription__c has a foreign key relationshipship with object1__c and is named subscription__r.

 

I get the error Catchable fatal error: Object of class SObject could not be converted to string in...

 

I know this is probably very simple, but not seeing it.

 

Sean FieldingSean Fielding

As a workaround, I simply pass the xml equivalent

 

"<type>Subscription__c</type><buying_email_address__c>$data[0]</buying_email_address__c>