Hey everyone. I have a case, when I run 2 requests that are subsequent with each other.
But the subrequest is run in a loop, and the only way to avoid it, is to chain requests using composite.
I have no idea how to implement this feature in the apex itself, so maybe someone has an example, or had a similar case to deal with.
Perhaps you can help me
#Apex #HTTP Callouts #API #Salesforce Developer
Hello @Maksym Kasyanchuk
,
You can use the output of one request as the input to a subsequent request. The response bodies and HTTP statuses of the requests are returned in a single response body. The entire series of requests counts as a single call toward your API limits.
For example, the following composite request body includes two subrequests. The first creates an account and designates the output as refAccount. The second creates a contact parented under the new account by referencing refAccount in the subrequest body.
{
"compositeRequest" : [{
"method" : "POST",
"url" : "/services/data/v63.0/sobjects/Account",
"referenceId" : "refAccount",
"body" : { "Name" : "Sample Account" }
},{
"method" : "POST",
"url" : "/services/data/v63.0/sobjects/Contact",
"referenceId" : "refContact",
"body" : {
"LastName" : "Sample Contact",
"AccountId" : "@{refAccount.id}"
}
}]
}
Refer to this: Send Multiple Requests Using Composite