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
WebNXWebNX 

Insert into custom object using PHP

I am trying to insert a custom object into another custom object which is its master. I cannot get salesforce's php toolkit to insert into any object. I can query the master custom object along with querying the child custom object. I am using salesforce enterprise, below is my code in which I am trying to do the insert.

 

Can someone, any one can help me. Thanks in advance.

 

 

$sObject = new stdClass();
$sObject->CurrencyIsoCode = 'USD';
$sObject->Downloader__c = 'PHP Test';
$sObject->Package__c = 'Test PHP';
$sObject->Product_Trial__c = 'XXXXXXXXXXXXXXX';

$upsertResponse = $this->_mySforceConnection->upsert('NSP_Trial_Download__c', array($sObject),$objectType);
echo "Upserting New NSP_Trial_Download__c\(existing)r\n";
print_r($upsertResponse);

catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;

}

 

Best Answer chosen by Admin (Salesforce Developers) 
Pat PattersonPat Patterson

Hi Web Head,

 

The first argument to upsert() should be the name of the external ID field - it looks like you're using something else - 'NSP_Trial_Download__c' doesn't appear in the list of fields you're setting in your record. See this upsert sample - it uses 'Email' as the external ID field on the 'Contact' standard object: http://wiki.developerforce.com/page/PHP_Toolkit_20.0_Upsert_Sample_%28Enterprise%29

 

Cheers,


Pat

All Answers

Vishal Gaddi6Vishal Gaddi6

Hey !!!

 

$upsertResponse = $this->_mySforceConnection->upsert('NSP_Trial_Download__c', array($sObject),$objectType);

 

I am also working on something like this. 

I dont think you can use above command i.e. using a DML in another DML.

You will have to first insert the Master record first, then get its Salesforce ID and then create the Child record with tht Salesforce ID.

WebNXWebNX

Hey Vishal,

 

Thanks for the reply, but I should be able to upsert to any object custom or not. I can't get the my php toolkit to upsert to any object give the ID from Salesforce; are you able to upsert any thing?

Pat PattersonPat Patterson

Hi Web Head,

 

The first argument to upsert() should be the name of the external ID field - it looks like you're using something else - 'NSP_Trial_Download__c' doesn't appear in the list of fields you're setting in your record. See this upsert sample - it uses 'Email' as the external ID field on the 'Contact' standard object: http://wiki.developerforce.com/page/PHP_Toolkit_20.0_Upsert_Sample_%28Enterprise%29

 

Cheers,


Pat

This was selected as the best answer