You need to sign in to do that
Don't have an account?
How do I upsert using Id as the External ID with the REST API?
The REST API documentation states that you can use the Salesforce record ID as an external ID for upserting data.
This example uses the POST method as a special case to insert a record where the Id field is treated as the external ID. Because the value of Id is null, it’s omitted from the request. This pattern is useful when you’re writing code to upsert multiple records by different external IDs and you don’t want to request a separate resource. POST using Id is available in API version 37.0 and later.
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm
How is this any benefit? Upsert calls with a true external ID all use the PATCH method, but using a Salesforce ID requires POST for new records and PATCH for updating records. With a Salesforce ID, you cannot PATCH a new record, and you cannot POST to an existing record, and the /Id/ part of the path appears to be redundant and unnecessary. How is this pattern actually useful?
If you've got the Salesforce record ID, you'll have to use PATCH to update the record. You can't use POST to insert a record by ID as the ID is generated by Salesforce.
I'm trying to understand the pattern you want to use. Can you clarify? Thanks
- To insert using Salesforce ID as an external ID, which implies your ID value is null
- POST to [instance_url]/services/data/v51.0/Account/Id
- To update using Salesforce ID as an external ID
- PATCH to [instance_url]/services/data/v51.0/Account/Id/[salesforce_id]
Now, forget about the "using Salesforce ID as an external ID" part:- To insert
- POST to [instance_url]/services/data/v51.0/Account
- To update using a Salesforce ID
- PATCH to [instance_url]/services/data/v51.0/Account/[salesforce_id]
The only difference between the two scenarios is the presence of "/Id/" in the URL path…so why even include it at all? Why is it described in the documentation about "upserting" when such an action is not actually possible using a Salesforce record ID?