Newer Version Available
Update Records Using sObject Collections
Use a PATCH request with sObject Collections to update up to 200 records, returning a
list of SaveResult objects. You can choose whether to roll back the entire request when an
error occurs.
- The list can contain up to 200 objects.
- The list can contain objects of different types, including custom objects.
- Each object must contain an attributes map. The map must contain a value for type.
- Each object must contain an id field with a valid ID value.
- Objects are updated in the order they’re listed. The SaveResult objects are returned in the order in which the update requests were specified.
- If the request body includes objects of more than one type, they are processed as chunks. For example, if the incoming objects are {account1, account2, contact1, account3}, the request is processed in three chunks: {{account1, account2}, {contact1}, {account3}}. A single request can process up to 10 chunks.
- You can’t update records for multiple object types in one call when one of those types is related to a feature in the Salesforce Setup area.
If the request isn’t well formed, the API returns a 400 Bad Request HTTP Status. Fix the syntax of the request and try again. If the request is well formed, the API returns a 200 OK HTTP Status. If an item was processed successfully, the success flag shows for that item. Error information is returned in the errors array.
Syntax
- URI
- /services/data/vXX.X/composite/sobjects/
- Formats
- JSON, XML
- HTTP Method
- PATCH
- Authentication
- Authorization: Bearer token
- Parameters
-
Parameter Description allOrNone Optional. Indicates whether to roll back the entire request when the update of any object fails (true) or to continue with the independent update of other objects in the request. The default is false. records Required. A list of records. Set the id and type attribute for each record.
Example
- Example Request
-
1curl -X PATCH https://MyDomainName.my.salesforce.com/services/data/v62.0/composite/sobjects/ -H "Authorization: Bearer token" -H "Content-Type: application/json" -d "@exampleRequestBody.json" - Example Request Body
-
1{ 2 "allOrNone" : false, 3 "records" : [{ 4 "attributes" : {"type" : "Account"}, 5 "id" : "001xx000003DGb2AAG", 6 "NumberOfEmployees" : 27000 7 },{ 8 "attributes" : {"type" : "Contact"}, 9 "id" : "003xx000004TmiQAAS", 10 "Title" : "Lead Engineer" 11 }] 12} - Example Response Body
-
1HTTP/1.1 200 OK 2 3[ 4 { 5 "id" : "001RM000003oCprYAE", 6 "success" : true, 7 "errors" : [ ] 8 }, 9 { 10 "id" : "003RM0000068og4YAA", 11 "success" : true, 12 "errors" : [ ] 13 } 14] - Example Response Body (Some Items Failed and allOrNone is false)
-
1HTTP/1.1 200 OK 2 3[ 4 { 5 "id" : "001RM000003oCprYAE", 6 "success" : true, 7 "errors" : [ ] 8 }, 9 { 10 "success" : false, 11 "errors" : [ 12 { 13 "statusCode" : "MALFORMED_ID", 14 "message" : "Contact ID: id value of incorrect type: 001xx000003DGb2999", 15 "fields" : [ 16 "Id" 17 ] 18 } 19 ] 20 } 21] - Example Response Body (Some Items Failed and allOrNone is true)
-
1HTTP/1.1 200 OK 2 3[ 4 { 5 "id" : "001RM000003oCprYAE", 6 "success" : false, 7 "errors" : [ 8 { 9 "statusCode" : "ALL_OR_NONE_OPERATION_ROLLED_BACK", 10 "message" : "Record rolled back because not all records were valid and the request was using AllOrNone header", 11 "fields" : [ ] 12 } 13 ] 14 }, 15 { 16 "success" : false, 17 "errors" : [ 18 { 19 "statusCode" : "MALFORMED_ID", 20 "message" : "Contact ID: id value of incorrect type: 001xx000003DGb2999", 21 "fields" : [ 22 "Id" 23 ] 24 } 25 ] 26 } 27]