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 Nested Records
The following example creates two sets of nested records. The first set includes an account and two child contact records. The second set includes an account, one child account record, and one child contact record. The record data is provided in newrecords.json.
Example for creating two new accounts and their child records
1curl https://MyDomainName.my.salesforce.com/services/data/v67.0/composite/tree/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d "@newrecords.json"Example request body newrecords.json file for creating two new Accounts and their child records
1{
2"records" :[{
3 "attributes" : {"type" : "Account", "referenceId" : "ref1"},
4 "name" : "SampleAccount1",
5 "phone" : "1234567890",
6 "website" : "www.salesforce.com",
7 "numberOfEmployees" : "100",
8 "industry" : "Banking",
9 "Contacts" : {
10 "records" : [{
11 "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
12 "lastname" : "Smith",
13 "Title" : "President",
14 "email" : "sample@salesforce.com"
15 },{
16 "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
17 "lastname" : "Evans",
18 "title" : "Vice President",
19 "email" : "sample@salesforce.com"
20 }]
21 }
22 },{
23 "attributes" : {"type" : "Account", "referenceId" : "ref4"},
24 "name" : "SampleAccount2",
25 "phone" : "1234567890",
26 "website" : "www.salesforce.com",
27 "numberOfEmployees" : "52000",
28 "industry" : "Banking",
29 "childAccounts" : {
30 "records" : [{
31 "attributes" : {"type" : "Account", "referenceId" : "ref5"},
32 "name" : "SampleChildAccount1",
33 "phone" : "1234567890",
34 "website" : "www.salesforce.com",
35 "numberOfEmployees" : "100",
36 "industry" : "Banking"
37 }]
38 },
39 "Contacts" : {
40 "records" : [{
41 "attributes" : {"type" : "Contact", "referenceId" : "ref6"},
42 "lastname" : "Jones",
43 "title" : "President",
44 "email" : "sample@salesforce.com"
45 }]
46 }
47 }]
48}Example response body after successfully creating records and relationships
1{
2 "hasErrors" : false,
3 "results" : [{
4 "referenceId" : "ref1",
5 "id" : "001D000000K0fXOIAZ"
6 },{
7 "referenceId" : "ref4",
8 "id" : "001D000000K0fXPIAZ"
9 },{
10 "referenceId" : "ref2",
11 "id" : "003D000000QV9n2IAD"
12 },{
13 "referenceId" : "ref3",
14 "id" : "003D000000QV9n3IAD"
15 },{
16 "referenceId" : "ref5",
17 "id" : "001D000000K0fXQIAZ"
18 },{
19 "referenceId" : "ref6",
20 "id" : "003D000000QV9n4IAD"
21 }]
22}Once the request is processed, all six records are created with the parent-child relationships specified in the request.