[SalesForce] Upsert Multiple Records with external ID with REST API

I am trying to update multiple contact records via the REST API that have an external Id CustomField__c.

Is there any way to do this?

I've tried using Workbench, hitting

(POST) /services/data/v39.0/sobjects/Contact/CustomField__c

(PAYLOAD)

[{"LastName":"Jack",
  "CustomField__c":"0402236",
  "AssistantName":"Smith",
  "Languages__c":"0402236",
  "FirstName":"Jack"}]

But it returns back:

BAD_REQUEST
errorCode: BAD_REQUEST
message: CustomField__c is not an Id field.

Best Answer

You can't do this with the endpoint you're trying to use; the method only allows updating a single record at a time, and uses the following syntax:

(PATCH) /services/data/41.0/sobjects/Contact/CustomField__c/ExtIdValue

If you want to upload multiple records at once, use the Composite resource:

(POST) /services/data/41.0/composite

{
"compositeRequest" : [{
  "method" : "PATCH",
  "url" : "/services/data/v41.0/sobjects/Contact/CustomField__c/ExtIdValue",
  "body" : { "LastName" : "Jack", ... }
  }, ...]
}

You do not specify the external Id in the body, as it is specified in the URL. If you need to upload a larger number of records, consider using SOAP, Bulk, etc APIs. You might also be interested in the SObject Tree API, which is in the documentation. It allows up to 200 records per request, unlike the composite API's limit of 25 requests.