How to Only Update Salesforce Records Using External IDs in REST API

by Sudipta Deb | Jul 22, 2024 | Salesforce, Salesforce Summer 24 Release | 0 comments

Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

Before Summer 24 Release i.e. before API version 61, when you use the HTTP Patch call to do some update on record, Salesforce performs the upsert operation i.e. if the record found with matching external id, api call is going to update the matching record, but if there is no matching record with the external id, then api call is going to create the new record with the details provided in the HTTP call request body. So it is basically an upsert operation.

But after Summer 24 release i.e. API version 61, Salesforce is introducing a parameter which you can pass in the API call to make sure it will only do the update to the existing record and if the existing record not found, it is not going to create a new record. The process will stop there.

So in this blog post and youtube video, I am going to explain this powerful enhancement. Please provide your feedback what do you think about this new powerful feature. 

The form you have selected does not exist.

Watch The Video Or Read The Article (Or Do Both smile)

Pre-requisite

I have created one custom field, named "External Id" in the account object. After that I have populated the field with some values in one of the existing Account record.

Also I have configured postman to connect with my Salesforce instance so that I can perform the HTTP call from there directly. I have published a video with the steps needed to connect Postman with Salesforce org. Sharing the video below just in case you need.

HTTP Call - Matching Existing Record

I have passed the external id value as 123456789 which I know is already there in the account named Burlington Textiles Corp of America. In the body of the HTTP call, I have provided is below and the HTTP call looks like -

{
 "Name":"Burlington Textiles Corp of America",
 "Active__c": "No",
 "AccountNumber" : "ABCD1234"
}

As you can see in the above screenshot, I have added a parameter ?updateOnly=true. This is the new paramater that is being introduced in Summer 24 release i.e. API version 61. In the Path variable, I have provided SOBJECT_API_NAME as Account, EXTERNAL_ID as External_Id__c and RECORD_ID as 123456789.

Basically I am trying to update the existing record matching external id with the values provided in the body of the request. Now after executing this HTTP Patch call, below is the response, which indicates API call has successfully updated the existing record and not created any new record. If I now go to my account record, I will also notice the AccountNumber is changed to ABCD1234 for Burlington Textiles Corp of America

HTTP Call - Matching No Existing Record

I have passed the external id value as 1111 which I know is not there in any of the existing account. The body of the HTTP request is same. Call looks like -

As you can see in the above screenshot, I have added a parameter ?updateOnly=true. This is the new paramater that is being introduced in Summer 24 release i.e. API version 61. In the Path variable, I have provided SOBJECT_API_NAME as Account, EXTERNAL_ID as External_Id__c and RECORD_ID as 1111.

Basically I am trying to update the existing record matching external id with the values provided in the body of the request. Now after executing this HTTP Patch call, below is the response, which indicates API call has not found any matching record. So instead of creating a new record, the process stopped here. 

Final Thoughts

To prevent creating a new record if the target record can’t be found or doesn’t exist, add the updateOnly parameter to a URL that executes an upsert operation. You can also use URLs with the updateOnly parameter in composite REST API and composite graph REST API.

Disclaimer

This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.

0 Comments

Leave a Reply

Written by Sudipta Deb

Enterprise Cloud Architect, Content Creator, 20x Salesforce Certified, 1x Google Cloud Certified, 2x Copado Certified

Related Posts

Salesforce Cancels the “Permissions in Profiles” Retirement: What It Means for Admins and Architects

Salesforce Cancels the “Permissions in Profiles” Retirement: What It Means for Admins and Architects

For the last few years, Salesforce administrators, architects, and security teams have been preparing for a major platform change: the retirement of permissions managed directly through Profiles. Salesforce had previously announced plans to move organizations toward a Permission Set–led security model, with enforcement expected to begin around the Spring ’26 timeframe.

read more...

0 Comments

Leave a Reply