Newer Version Available

This content describes an older version of this product. View Latest

Upsert an Account and Create a Contact

The following example uses the Composite resource to upsert an account and create a contact that is linked to the account. All these requests are executed in a single call. The composite.json file contains the composite request and subrequest data.
Upsert an account and create a contact
1curl https://MyDomainName.my.salesforce.com/services/data/v59.0/composite/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d "@composite.json"
Request body composite.json file
1{
2    "allOrNone" : true,
3    "compositeRequest": [{
4        "method": "PATCH",
5        "url": "/services/data/v59.0/sobjects/Account/ExternalAcctId__c/ID12345",
6        "referenceId": "NewAccount",
7        "body": {
8            "Name": "Acme"
9        }
10    },{
11        "method" : "POST",
12        "url" : "/services/data/v59.0/sobjects/Contact",
13        "referenceId" : "newContact",
14        "body" : {
15            "LastName" : "Harrison",
16            "AccountId" : "@{NewAccount.id}"
17        }
18    }]
19}
Response body after successfully executing the composite request
1{
2    "compositeResponse" : [{
3        "body" : {
4            "id" : "0016g00000Wqu1EAAR",
5            "success" : true,
6            "errors" : [ ],
7            "created" : true
8        },
9        "httpHeaders" : {
10            "Location" : "/services/data/v59.0/sobjects/Account/0016g00000Wqu1EAAR"
11        },
12        "httpStatusCode" : 201,
13        "referenceId" : "NewAccount"
14    },{
15        "body" : {
16            "id" : "0036g00000WKnfLAAT",
17            "success" : true,
18            "errors" : [ ]
19        },
20        "httpHeaders" : {
21            "Location" : "/services/data/v59.0/sobjects/Contact/0036g00000WKnfLAAT"
22        },
23        "httpStatusCode" : 201,
24        "referenceId" : "newContact"
25    }]
26}