Salesforce REST API Composite Resources

In this blog, I am going to explain salesforce rest API composite resource which is designed to reduce the number of round trips to the server.  A composite API is a sequence of tasks that run synchronously and  Composite API is built by combing the existing API functions that can perform the multiple tasks in the single call. Salesforce composite resources contain Composite, Tree, batch resources.

A composite API may be used :

  • To speed up the execution of a sequence of tasks instead of making separate calls
  • To compose an API by creating a sequence of web services
  • Composite API run synchronously

Salesforce provides three composite resources namely composite, batch, tree
composite/: Executes a series of REST API requests in a single call. You can use the output of one request as the input to a subsequent request.
composite/batch/: Execute a set of subrequests in a single request. Subrequests are executed independently and information can’t be passed between subrequest calls.
composite/tree/: Creates one or more sObject trees with root records of the specified type. An sObject tree is a collection of nested, parent-child records with a single root record.

Composite Resource 
Composite Resource Executes a series of REST API requests in a single call. You can use the output of one request as the input to a subsequent request. .The requests in a composite call are called subrequests. All subrequests are executed in the context of the same user. In a subrequest’s body, you specify a reference ID that maps to the subrequest’s response. You can then refer to the ID in the URL or body fields of later subrequests by using a JavaScript-like reference notation. Let us consider you wanted to create a work order and work order items on the same call.The following examples contain two subqueries where the first request creates a work order and for the second request, we will pass create a work order items where we will pass the referenceId on the first request.