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
Debbie61Debbie61 

Need help getting web service update using foreign key to work

According to the SFC documentation, if I designate a field in my custom object as an external id ( which I did), and then set the value of the field in the webservice (which I did), that SFC will perform the udpate using the foreign key instead of a SFC Id ( this did not happen).

 

I have a custom object called : dmb_survey__c

I checked field for external id: project_task_id__c

I set the field value in my web service code :

dmb.project_task_id__c = row.task_id;

I call the SFC update :

SaveResult[] saveResults = binding.update(updateArray);  

 

SFC returns the following error message:

"ERROR Message: Id not specified in an update call"

Well, its not specified because SFC claims you do not need it if you have a foreign key. What am I missing here?

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Is project_task_id__c a numeric field, are you using .NET, if so you need to set the specified flag (project_task_id__cSpecified = true), see the sticky in the .NET board.

All Answers

SuperfellSuperfell

You have to call upsert.

Debbie61Debbie61

If I have to use Upsert that forces me to only do one update at a time as it seems to require me to send it the actual value

of the foreign key instead of just saying find the foreign key in this field. Is that correct?  Or is there a way to pass

an entire array?

 

Thanks for your help Simon

 

Here is the documenation from SFC that implies you can use update:

 

public void updateForeignKeySample()
{
  Opportunity updateOpportunity = new Opportunity();
  updateOpportunity.setStageName("Prospecting");
  updateOpportunity.setId(new ID("006300000023YFu"));
  // Standard object ref
  Account updateParentAccountRef = new Account();
  updateParentAccountRef.setExternal_SAP1_ACCTID__c("SAP111111"); 
  updateOpportunity.setAccount(updateParentAccount);
  // call update
  UpdateResult[] updateResults = binding.update(new SObject[] {updateOpportunity});
  // check results and do more processing after the update call ...
}


 

 

Debbie61Debbie61

I am using upsert but I am getting an error message. I call upsert like this:

 

UpsertResult[] upsertResults = binding.upsert("project_task_id__c", updateArray);

 

But SFC sends back an error that states: project_task_id__c not specified.

I am still setting the value in my code

dmb.project_task_id__c = row.task_id;
dmbUpdateArray[j++] = dmb;
logger.WriteEntry("Project task id " + dmb.project_task_id__c);

 

 And my log shows I am populating the value: 

Project task id 668152

SuperfellSuperfell

Using update you can use the externalId of related records to set foreign key values, but you need to specify the salesforce.com Id of the actual record being updated. (as per the sample code you posted, it sets the salesforce.com id of the opportunity being updated, but uses the externalId field on the account to set the account relationship of the opportunity. 

SuperfellSuperfell

Is project_task_id__c a numeric field, are you using .NET, if so you need to set the specified flag (project_task_id__cSpecified = true), see the sticky in the .NET board.

This was selected as the best answer
Debbie61Debbie61

Simon,

That was the solution to the problem. Thank you so much! I could have been pulling my hair out days

and babbling to myself "there is nothing wrong with this code...."

 

You saved the day!