Reputation: 726
In the Salesforce Bulk API documentation there are examples of how to do insert, upsert, update, and query operations. But examples on delete operation is not available.
In the bulk API documentation it says;
Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. You can use it to query, queryAll, insert, update, upsert, or delete many records asynchronously by submitting batches. Salesforce processes batches in the background.
But delete and queryAll documentation and examples are missing. Can someone provide an example on delete operation?
Upvotes: 2
Views: 7645
Reputation: 130
I have been facing this very problem myself trying to make an API integration that maintains Event entries in Salesforce.
All of these examples are in json but they should be easily translatable to csv and xml respectively.
Deleting from the Event object requires a job, as with all operations, and the example job request that I have been using and sent to <your salesforce site>/services/async/48.0/job/
looks as follows:
{
"operation": "delete",
"object": "Event",
"concurrencyMode": "Parallel",
"contentType": "JSON"
}
The server then replies with something along the lines of (some items omitted for brevity)
{
"apexProcessingTime": 0,
"apiActiveProcessingTime": 0,
"apiVersion": 48.0,
"assignmentRuleId": null,
"concurrencyMode": "Parallel",
"contentType": "JSON",
...
"numberRetries": 0,
"object": "Event",
"operation": "delete",
"state": "Open",
"systemModstamp": "2020-04-08T15:13:42.000+0000",
"totalProcessingTime": 0
}
You then create batches as per norm at <your salesforce>/services/async/48.0/job/<jobId>/batch/
except delete batches can only contain Ids for the items you want to delete, for instance [{"Id":"00U5I00000145XcUAI"},{"Id":"00U5I00000145XdUAI"},{"Id":"00U5I00000145XeUAI"},{"Id":"00U5I00000145XgUAI"},{"Id":"00U5I00000145XhUAI"}]
.
After the batch completes and either fails or completes successfully, you can retrieve your results by sending the usual requests to get your result ids and then the results from those result ids. I didn't do anything different from a query operation on the Bulk API.
In my case, the server responded with
[ {
"success" : true,
"created" : false,
"id" : "00U5I00000145XcUAI",
"errors" : [ ]
}, {
"success" : true,
"created" : false,
"id" : "00U5I00000145XdUAI",
"errors" : [ ]
}, {
"success" : true,
"created" : false,
"id" : "00U5I00000145XeUAI",
"errors" : [ ]
}, {
"success" : true,
"created" : false,
"id" : "00U5I00000145XgUAI",
"errors" : [ ]
}, {
"success" : true,
"created" : false,
"id" : "00U5I00000145XhUAI",
"errors" : [ ]
} ]
The lack of an official guide on these operations that are very possible to do surprised me, but here's hoping that someone can get some use of this belated reply to your question.
Upvotes: 4
Reputation: 2759
The semantics of Bulk API deletes are essentially the same as inserts or updates: you create a job, with the operation set to "delete"
or "hardDelete"
, and then you post batches of record data against it. For a deletion, you include only the record Id in the batches, rather than updateable or insertable record content.
For that reason, implementations of Bulk API delete typically just collapse to a different parameter to the same underlying architecture. See examples in your Salesforce connector library of choice, such as
Bulk API 2.0 uses a different model, but deletions similarly collapse to a different parameter when ingesting the data. See implementation in
Upvotes: 3