Newer Version Available
Upsert Records Using sObject Rows by External ID
- If the external ID doesn't match an existing record, then a new record is created according to the request body. To prevent a new record from being created, use the updateOnly parameter.
- If the external ID matches one existing record, then the existing record is updated according to the request body.
- If the external ID matches multiple existing records, then a 300 error is returned, and no records are created or updated.
If you’re upserting a record for an object that has a custom field with both the External ID and Unique attributes selected (a unique index), you don’t need any special permissions. The Unique attribute prevents the creation of duplicates. If you’re upserting a record for an object that has the External ID attribute selected but not the Unique attribute selected (a non-unique index), your client application must have the permission “View All Data” to execute this call.
Syntax
- URI
- /services/data/vXX.X/sobjects/sObject/fieldName/fieldValue
- Formats
- JSON, XML
- HTTP Method
- PATCH
- Authentication
- Authorization: Bearer token
- Parameters
-
Parameter Description updateOnly An optional parameter that prevents a new record from being created. Forces the upsert to behave like an update when updateOnly=true is used.
Example
For examples of creating and updating records based on external IDs, see Insert or Update (Upsert) a Record Using an External ID.