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
benfaustbenfaust 

External IDs and "upsert" in PHP

Hello,
 
We're using the following bit of code (not exhaustively provided here) to upsert a Lead. The resulting error states the external ID does not exist. We have created a custom field for Leads called "emailid" in the account to which this code is attempting to upsert the Lead. Any ideas why this is not working?
 

$sObject = new SObject();

$sObject->fields=$FIELDS;

$sObject->type=$data["salesforce_type"];

$sObject->emailid=$data["email"];

$sfresults=$client2->upsert('emailid',array($sObject));

 

Perhaps something as simple as a working example using real strings (vs variables) would provide all the  direction we need to get this working.

 

Thanks,

-Ben

SuperfellSuperfell
i) when you created the custom field, did you check the external Id checkbox ?
ii) custom fields names end in __c, so you should be referering to the field as emailid__c

benfaustbenfaust
Yes, the external ID checkbox is checked.
SuperfellSuperfell
and you're using emailid__c (unlike your original post) ?
benfaustbenfaust
No, just 'emailid'... Does __c need to follow it?
SuperfellSuperfell
Yes, as per my earlier reply
ii) custom fields names end in __c, so you should be referering to the field as emailid__c
benfaustbenfaust
It still says this custom field is undefined.
SuperfellSuperfell
You have a naming problem, I'd use the sforce explorer or some similar tool to examine your schema to work out the correct name.
benfaustbenfaust

Thanks. It actually was working, but returning a different error which we were able to resolve.

I recall reading in documentation that in order to use upsert, a custom field must be created and marked as an external ID. So the question is this: Is there no way to use the default and existing e-mail field without having to make any modifications? If not, how will changes be made to the accounts of every user who uses our system?

ToreTore
I have the same question.  It would be great to not have to store the email in two different fields simply for the sake of getting upsert to recognize email as an external id, but I don't see any other way, other than searching for a contact by email and if finding it update else insert it.

Also, is there a way to send a bulk upsert to reduce the number of calls to SF?