function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cedric MarfilCedric Marfil 

Composite Graph API CollateSubrequests

Hi there,
Hope all is fine for you. I'm working on Integrations between ERP and Salesforce and willing to use Composite Resources to transfer Orders from our ERP to Salesforce.
Issue is that, even if it works most of the time, I'm having issues when Order contains more than X number of lines as Composite API allows up to 25 Subrequests only. I then discovered the Composite Graph API which raised this limit to 500, which was then pretty much OK, until I figured out that my subrequests were not executed in Order. Looking into documentation, I found the CollateSubrequests parameter, but this one seems to be only available in Composite API (back to the limit of 25 subrequests).
Does anybody know if there is a way to guarantee the order of execution for my subrequests in a Composite Graph API (for some Business reasons, I have to respect this order of execution which requires me to update the Order first (to Unlock it), then Delete Some Order Lines (which has to happen before I change the Currency on the Order), then Update the Order again (for currency), then re-Insert my Order Lines, then finally update my Order (to Lock it back).

Thanks in advance for your advices here

Cédric
Shri RajShri Raj
You are correct that the CollateSubrequests parameter is only available in the Composite API, and it is not available in the Composite Graph API. The Composite Graph API does not guarantee the order of execution of subrequests.
However, you can still achieve your desired order of execution by using the composite-tree resource type in the Composite API. The composite-tree resource type is designed for hierarchical data structures, and it allows you to define a tree of related records to be created or updated in a single request.
Here's an example of how you could use the composite-tree resource type to create or update an order with multiple order lines in the correct order:
Create a new Order record using a POST request to the sobjects resource.
Create an array of subrequests for the order lines that you want to delete. Set the method parameter to DELETE, and include the ID of each order line that you want to delete. Add these subrequests to the records array of the Order record that you created in step 1.
Create a subrequest to update the order to change the currency.
Create an array of subrequests for the order lines that you want to insert. Set the method parameter to POST, and include the data for each order line that you want to insert. Add these subrequests to the records array of the Order record.
Create a final subrequest to update the order to lock it.
Here's an example JSON payload for a Composite API request that creates an order with two order lines, deletes one of the order lines, updates the order currency, re-inserts the order line, and updates the order to lock it:
{
    "compositeRequest": [
        {
            "method": "POST",
            "url": "/services/data/v52.0/sobjects/Order",
            "referenceId": "orderRef",
            "body": {
                "field1": "value1",
                "field2": "value2"
            },
            "children": [
                {
                    "method": "DELETE",
                    "url": "/services/data/v52.0/sobjects/OrderLine/001xxxxxxxxxxxxxxx",
                    "referenceId": "orderLine1"
                }
            ]
        },
        {
            "method": "PATCH",
            "url": "/services/data/v52.0/sobjects/Order/{!orderRef.Id}",
            "referenceId": "updateOrder",
            "body": {
                "field3": "newCurrency"
            },
            "children": [
                {
                    "method": "POST",
                    "url": "/services/data/v52.0/sobjects/OrderLine",
                    "referenceId": "orderLine2",
                    "body": {
                        "field4": "value4",
                        "field5": "value5",
                        "Order__c": "{!orderRef.Id}"
                    }
                }
            ]
        },
        {
            "method": "PATCH",
            "url": "/services/data/v52.0/sobjects/Order/{!orderRef.Id}",
            "referenceId": "lockOrder",
            "body": {
                "field6": "locked"
            }
        }
    ]
}

 
Cedric MarfilCedric Marfil
Hi Shri Raj,
Thanks very much for the detailed explanation. Is that using the standard /services/data/vXX.X/composite URL as I cannot find any documentation about the Composite Tree online. There seems to be a /services/data/vXX.X/composite/tree/sObjectName URL, but this allows only INSERT as I understand.
Any link to the documentation would be greatly appreciated here.

Thansk in advance

Cédric