1

Let's say I have an external identifier field Account.External_Id__c.

I have a web application which has the values for this field and needs to delete multiple records, (e.g. "Abc123", "Abc124", etc".)

Is it possible, using Salesforce native APIs, to make a single request which would delete all the desired records?

If so, how?

2

2 Answers 2

2

This is definitely possible using a simple Composite Graph API, you will need to a POST request to the below URL

/services/data/v51.0/composite/graph

The sample request is as below

{
"graphs" : [
    {
        "graphId" : "1",
        "compositeRequest" : [
            {
                "url" : "/services/data/v51.0/sobjects/Account/ExpId__c/123",
                "method" : "DELETE",
                "referenceId" : "reference_id_account_1"
            },
            {
                "url" : "/services/data/v51.0/sobjects/Account/ExpId__c/124",
                "method" : "DELETE",
                "referenceId" : "reference_id_account_2"
            }
        ]
    }
  ]
}

You can go up to 500 records using this.

Note I assume that the ExpId__c is an external Id on Account objects.

If you are happy building some apex, a custom rest service in apex can also be an option.

With this, you can easily go up to 5-10K records per request.

If you want to delete large volumes Bulk API v2.0 is an option. You will use a simple ingest job v2.0 with delete operation

You will need to however implement the BULK API v2.0 using Node.js or Java or any other language of your choice.

7
  • thanks for the response. This looks promising. Does composite graph allow for an "all or none" or "best effort" option? I guess for "best effort" each would need to be in a separate graph? Also, if I won't use the reference ids, do I need to include them? May 21, 2021 at 11:52
  • 1
    @Brian No! Unfortunately graph api is either everything in the batch (or graph) is deleted or nothing if one record fails! One way to improve the efficiency would be to have at least 50 nodes with each nodes having 10 rows! That way if something fails just those 10 records are skipped! May 21, 2021 at 11:55
  • 1
    There is a limit on number of nodes! developer.salesforce.com/docs/atlas.en-us.api_rest.meta/… it is 75 or something! May 21, 2021 at 11:59
  • 1
    I would just use bulk api V2.0 if load volumes are higher and I need granular control or an apex rest service with database.delete May 21, 2021 at 12:02
  • 1
    ... Always tradeoffs. Bulk API adds complexity on the consumer, Custom REST Resource adds complexity on Salesforce. I was hoping for a simpler solution which would be more consistent with inserting data.... Anyway, thanks for the responses. I'll leave it open for awhile just to see if anyone else knows a different way that I might like better, but if not I'll accept it later. :-) May 21, 2021 at 12:17
0

DELETE Request (A list of up to 200 IDs of objects is supported )

/services/data/v57.0/composite/sobjects?ids={RECORDID1},{RECORDID2},{RECORDID3},{RECORDID4}&allOrNone=false

Response

[
    {
        "id": "RECORDID1",
        "success": true,
        "errors": []
    },
    {
        "id": "RECORDID2",
        "success": true,
        "errors": []
    },
    {
        "id": "RECORDID3",
        "success": true,
        "errors": []
    },
    {
        "id": "RECORDID4",
        "success": true,
        "errors": []
    }
]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .