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
vb13vb13 

PHP Sample Code for Foreign Key Usage

Hi, Does anyone has php sample code for http://www.pocketsoap.com/weblog/2008/09/1824.html (also see the example upsert() - Foreign Keys section in the manual).
Best Answer chosen by Admin (Salesforce Developers) 
vb13vb13
I worked this one out. I am updating a Task a linking it to an account using a custom account key Publisher_NUM__c.

Here is the code snippet that create the sObject:


    $sfData = array('Subject' => $this->subject,
                          'Description'=>$this->description,
                          'Status' => 'Completed',
                          'Type__c' => $this->type   //I have a custom type on the Task
                          );
                         
      $sObject = new SObject();
    $sObject->fields = $sfData;
    $sObject->type = 'Task';
   
    $sObject->fields['What'] = "<type>Account</type><Publisher_NUM__c>$sfAccount</Publisher_NUM__c>";  //$sfAccount the the value of my account foreign key

I user a SF create(array($sObject)) call. You can also use upsert if you have your custom primary key on Task.
   

All Answers

SCenTSCenT
Hi,
I've been struggling with the same thing. Can anybody help? For now I'm using triggers, but there's got to be an cleaner solution right?

Thanks in advance!

vb13vb13
I worked this one out. I am updating a Task a linking it to an account using a custom account key Publisher_NUM__c.

Here is the code snippet that create the sObject:


    $sfData = array('Subject' => $this->subject,
                          'Description'=>$this->description,
                          'Status' => 'Completed',
                          'Type__c' => $this->type   //I have a custom type on the Task
                          );
                         
      $sObject = new SObject();
    $sObject->fields = $sfData;
    $sObject->type = 'Task';
   
    $sObject->fields['What'] = "<type>Account</type><Publisher_NUM__c>$sfAccount</Publisher_NUM__c>";  //$sfAccount the the value of my account foreign key

I user a SF create(array($sObject)) call. You can also use upsert if you have your custom primary key on Task.
   
This was selected as the best answer