Newer Version Available
Create Multiple Records
While the sObject Tree resource can be used to create nested records, you can also create multiple, unrelated
records of the same type. In a single request, you can create up to two hundred records. In
the request data, you supply the required and optional field values for each record, each
record’s type, and a reference ID for each record, and then use the POST method of the
resource. The response body will contain the IDs of the created records if the request is
successful. Otherwise, the response contains only the reference ID of the record that caused
the error and the error information.
The following example creates four new accounts. The record data is provided in newrecords.json.
- Example for creating four new accounts
-
1curl https://yourInstance.salesforce.com/services/data/v55.0/composite/tree/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d "@newrecords.json" - Example request body newrecords.json file for creating four new accounts
-
1{ 2"records" :[{ 3 "attributes" : {"type" : "Account", "referenceId" : "ref1"}, 4 "name" : "SampleAccount1", 5 "phone" : "1111111111", 6 "website" : "www.salesforce.com", 7 "numberOfEmployees" : "100", 8 "industry" : "Banking" 9 },{ 10 "attributes" : {"type" : "Account", "referenceId" : "ref2"}, 11 "name" : "SampleAccount2", 12 "phone" : "2222222222", 13 "website" : "www.salesforce2.com", 14 "numberOfEmployees" : "250", 15 "industry" : "Banking" 16 },{ 17 "attributes" : {"type" : "Account", "referenceId" : "ref3"}, 18 "name" : "SampleAccount3", 19 "phone" : "3333333333", 20 "website" : "www.salesforce3.com", 21 "numberOfEmployees" : "52000", 22 "industry" : "Banking" 23 },{ 24 "attributes" : {"type" : "Account", "referenceId" : "ref4"}, 25 "name" : "SampleAccount4", 26 "phone" : "4444444444", 27 "website" : "www.salesforce4.com", 28 "numberOfEmployees" : "2500", 29 "industry" : "Banking" 30 }] 31} - Example response body after successfully creating records
-
1{ 2 "hasErrors" : false, 3 "results" : [{ 4 "referenceId" : "ref1", 5 "id" : "001D000000K1YFjIAN" 6 },{ 7 "referenceId" : "ref2", 8 "id" : "001D000000K1YFkIAN" 9 },{ 10 "referenceId" : "ref3", 11 "id" : "001D000000K1YFlIAN" 12 },{ 13 "referenceId" : "ref4", 14 "id" : "001D000000K1YFmIAN" 15 }] 16}