Composite Graph in Salesforce
Composite Graph in Salesforce is similar to Composite Request. But, this has higher limit. Powerful API request to avoid multiple API calls to Salesforce.
Regular composite requests allow you to execute a series of REST API requests in a single call. And you can use the output of one request as the input to a subsequent request.
Composite graphs extend this by allowing you to assemble a more complicated and complete series of related objects and records.
Composite graphs also enable you to ensure that the steps in a given set of operations are either all completed or all not completed. This avoids requiring you to check for a mix of successful and unsuccessful results.
Regular composite requests have a limit of 25 sub-requests. Composite graphs increase this limit to 500. This gives a single API call much greater power.
Example:
Using the below body, I am creating two requests.
Request 1:
Parent Account 1(Account Record)
Child Account 1(Child Account Record to Parent Account 1)
Test 2 Test 2(Contact Record to Child Account 1)
Test 1 Test 1(Contact Record to Parent Account 1)
Request 2:
Parent Account 2(Account Record)
Child Account 2(Child Account Record to Parent Account 1)
Test 4 Test 4(Contact Record to Child Account 2)
Test 3 Test 3(Contact Record to Parent Account 2)
POST Body:
{
"graphs":[
{
"graphId":"1",
"compositeRequest":[
{
"url":"/services/data/v50.0/sobjects/Account/",
"body":{
"name":"Parent Account 1",
"description":"Parent account"
},
"method":"POST",
"referenceId":"reference_id_account_1"
},
{
"url":"/services/data/v50.0/sobjects/Account/",
"body":{
"name":"Child Account 1",
"description":"Child account",
"ParentId":"@{reference_id_account_1.id}"
},
"method":"POST",
"referenceId":"reference_id_account_2"
},
{
"url":"/services/data/v50.0/sobjects/Contact/",
"body":{
"FirstName":"Test 1",
"LastName":"Test 1",
"AccountId":"@{reference_id_account_1.id}"
},
"method":"POST",
"referenceId":"reference_id_contact_1"
},
{
"url":"/services/data/v50.0/sobjects/Contact/",
"body":{
"FirstName":"Test 2",
"LastName":"Test 2",
"AccountId":"@{reference_id_account_2.id}"
},
"method":"POST",
"referenceId":"reference_id_contact_2"
}
]
},
{
"graphId":"2",
"compositeRequest":[
{
"url":"/services/data/v50.0/sobjects/Account/",
"body":{
"name":"Parent Account 2",
"description":"Parent account"
},
"method":"POST",
"referenceId":"reference_id_account_1"
},
{
"url":"/services/data/v50.0/sobjects/Account/",
"body":{
"name":"Child Account 2",
"description":"Child account",
"ParentId":"@{reference_id_account_1.id}"
},
"method":"POST",
"referenceId":"reference_id_account_2"
},
{
"url":"/services/data/v50.0/sobjects/Contact/",
"body":{
"FirstName":"Test 3",
"LastName":"Test 3",
"AccountId":"@{reference_id_account_1.id}"
},
"method":"POST",
"referenceId":"reference_id_contact_1"
},
{
"url":"/services/data/v50.0/sobjects/Contact/",
"body":{
"FirstName":"Test 4",
"LastName":"Test 4",
"AccountId":"@{reference_id_account_2.id}"
},
"method":"POST",
"referenceId":"reference_id_contact_2"
}
]
}
]
}
Output: