Newer Version Available
Update an Account, Create a Contact, and Link Them with a Junction Object
The following example uses the Composite resource to update some fields on an
account, create a contact, and link the two records with a junction object called AccountContactJunction. All these requests are executed in
a single call. The composite.json file contains the composite request
and subrequest data.
- Update an account, create a contact, and link them with a junction object
-
1curl https://MyDomainName.my.salesforce.com/services/data/v65.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/v65.0/sobjects/Account/001xx000003DIpcAAG", 6 "referenceId" : "UpdatedAccount", 7 "body" : { 8 "Name" : "Salesforce", 9 "BillingStreet" : "Landmark @ 1 Market Street", 10 "BillingCity" : "San Francisco", 11 "BillingState" : "California", 12 "Industry" : "Technology" 13 } 14 },{ 15 "method" : "POST", 16 "referenceId" : "NewContact", 17 "url" : "/services/data/v65.0/sobjects/Contact/", 18 "body" : { 19 "lastname" : "John Doe", 20 "Phone" : "1234567890" 21 } 22 },{ 23 "method" : "POST", 24 "referenceId" : "JunctionRecord", 25 "url" : "/services/data/v65.0/sobjects/AccountContactJunction__c", 26 "body" : { 27 "accountId__c" : "001xx000003DIpcAAG", 28 "contactId__c" : "@{NewContact.id}" 29 } 30 }] 31} - Response body after successfully executing the composite request
-
1{ 2 "compositeResponse" : [{ 3 "body" : null, 4 "httpHeaders" : { }, 5 "httpStatusCode" : 204, 6 "referenceId" : "UpdatedAccount" 7 }, { 8 "body" : { 9 "id" : "003R00000025R22IAE", 10 "success" : true, 11 "errors" : [ ] 12 }, 13 "httpHeaders" : { 14 "Location" : "/services/data/v65.0/sobjects/Contact/003R00000025R22IAE" 15 }, 16 "httpStatusCode" : 201, 17 "referenceId" : "NewContact" 18 }, { 19 "body" : { 20 "id" : "a00R0000000iN4gIAE", 21 "success" : true, 22 "errors" : [ ] 23 }, 24 "httpHeaders" : { 25 "Location" : "/services/data/v65.0/sobjects/AccountContactJunction__c/a00R0000000iN4gIAE" 26 }, 27 "httpStatusCode" : 201, 28 "referenceId" : "JunctionRecord" 29 }] 30}