Composite graphs provide an enhanced way to perform composite requests, which execute a series of REST API requests in a single call.
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 regular composite requests 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 requests are either all completed or all not completed. If you use this option, you don’t have to check which requests were successful.
Regular composite requests have a limit of 25 subrequests. Composite graphs increase this limit to 500.
Defining Composite Graphs
In general, a graph is a collection of connected nodes.
In the context of composite graph operations, the nodes are composite subrequests. For example, a node can be a composite subrequest like this:
A composite graph can be directed meaning that some nodes use information from other nodes. For example, a node that creates a Contact can use the ID of an Account node to link the Contact with the Account.
Nodes with no parents are considered to be at depth 1.
The depth of another node is the maximum number of edges in the graph from depth 1 to that node. An edge between two nodes occurs when the one node uses a property (such as @{reference_account.id} ) from another node.
The AllOrNone Parameter
In standard composite operations, the only control over what happens if an error occurs is the allOrNone parameter. If the value is true, the entire composite request is rolled back. If the value is false, the remaining subrequests that don’t depend on the failed subrequest are executed. Dependent subrequests aren’t executed, which can lead to a mix of processed and unprocessed records.
Composite graphs have the advantage that each graph is guaranteed to either complete all its subrequests successfully or to be rolled back completely. In other words, the allOrNone parameter is implicitly considered to be true for each graph. A composite graph request never results in a mix of processed and unprocessed records.
To ensure that graphs are independent, the following rules apply.
Subrequests in one graph can’t reference subrequests from another graph.
Each graph in one composite graph operation must be independent. If one graph can’t be processed successfully, that must not prevent other graphs in the same operation from being processed.
Best Practices
As a general practice, keep your graphs as small as possible. For example, it’s more efficient to have 50 graphs with 10 nodes rather than 1 graph with 500 nodes. Keeping graphs small has two advantages:
If one item in a graph fails, only the items in that graph are rolled back. It’s easier to identify and handle errors in smaller graphs.
The server can process multiple, smaller graphs faster and more efficiently.