Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Create Records Using sObject Collections
- 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.
- Objects are created in the order they’re listed. The SaveResult objects are returned in the order in which the create 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 create records for multiple object types in one call when one of the 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: POST
Authentication: Authorization: Bearer token
Parameters
| Parameter | Description |
|---|---|
| allOrNone | Optional. Indicates whether to roll back the entire request when the creation of any object fails (true) or to continue with the independent creation of other objects in the request. The default is false. |
| records | Required. A list of sObjects. In a POST request using sObject Collections, set the type attribute for each object, but don’t set the id field for any object. |
Note: If the sObject Collections request is embedded in a Composite request, the Composite request’s allOrNone parameter can also affect the results. See allOrNone Parameters in Composite and Collections Requests.
Example
Example Request
1curl -X POST https://MyDomainName.my.salesforce.com/services/data/v67.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 "Name" : "example.com",
6 "BillingCity" : "San Francisco"
7 }, {
8 "attributes" : {"type" : "Contact"},
9 "LastName" : "Johnson",
10 "FirstName" : "Erica"
11 }]
12}Example Response Body
1HTTP/1.1 200 OK
2
3[
4 {
5 "id" : "001RM000003oLnnYAE",
6 "success" : true,
7 "errors" : [ ]
8 },
9 {
10 "id" : "003RM0000068xV6YAI",
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 "success" : false,
6 "errors" : [
7 {
8 "statusCode" : "DUPLICATES_DETECTED",
9 "message" : "Use one of these records?",
10 "fields" : [ ]
11 }
12 ]
13 },
14 {
15 "id" : "003RM0000068xVCYAY",
16 "success" : true,
17 "errors" : [ ]
18 }
19]Example Response Body (Some Items Failed and allOrNone is true)
1HTTP/1.1 200 OK
2
3[
4 {
5 "success" : false,
6 "errors" : [
7 {
8 "statusCode" : "DUPLICATES_DETECTED",
9 "message" : "Use one of these records?",
10 "fields" : [ ]
11 }
12 ]
13 },
14 {
15 "success" : false,
16 "errors" : [
17 {
18 "statusCode" : "ALL_OR_NONE_OPERATION_ROLLED_BACK",
19 "message" : "Record rolled back because not all records were valid and the request was using AllOrNone header",
20 "fields" : [ ]
21 }
22 ]
23 }
24]