Bulk API 2.0 Query Delete

In this post, the Salesforce Bulk API 2.0 query will b used to delete some records. The Bulk query jobs allow asynchronous processing of SOQL queries because they are designed to handle queries that return large amounts of data (that is 10,000 records or more). The queries in Bulk API 2.0. support the following URIs and methods all of which will be used in this post except PATCH:
click http://hyperbaricnurses.org/17289-buying-viagra-25mg-tablets-online/ enter watch go to site cialis da 20 non funziona https://ramapoforchildren.org/youth/compare-business-plan-software-mac/47/ annoying habits essay gnstig viagra online breastfeeding and formula feeding essay writing contrast essay https://homemods.org/usc/make-up-essay/46/ source url https://norfolkspca.com/medservice/best-viagra-site-on-internet/14/ follow https://teamwomenmn.org/formatting/students-need-homework-essay/23/ overdose lasix go site essay sample scholarship coursework deadline tomorrow essay about reading is good habit levitra 1 get link writing a physics lab report click here https://aaan.org/indications/buy-bactrim-online-overnight-shipping/27/ who wrote the essay self reliance https://www.elc.edu/school/brain-drain-essay-300-words-pages/53/ castling the narrative essay how to write a research paper for science here URI: /services/data/vXX.X/jobs/query
HTTP Method: POST
Description: Creates a query job.

URI: /services/data/vXX.X/jobs/query
HTTP Method: GET
Description: Gets information about all query jobs in the org.

URI: /services/data/vXX.X/jobs/query/queryJobId
HTTP Method: GET
Description: Gets information about one query job.

URI: /services/data/vXX.X/jobs/query/queryJobId/results
HTTP Method: GET
Description: Gets the results for a query job.

URI: /services/data/vXX.X/jobs/query/queryJobId
HTTP Method: PATCH
Description: Aborts a query job.

URI: /services/data/vXX.X/jobs/query/queryJobId
HTTP Method: DELETE
Description: Deletes a query job.

Create a Query Job

Just like my post on Bulk Insert Records Using Bulk API 2.0, to delete records using Bulk API 2.0 query, Workbench (use your preference) will be used to create a job
(1) Log in to your Trailhead Playground or Developer Org and navigate to Workbench.
(2) On the Workbench page, for Environment, select Production. For API Version, select the highest available number from the dropdown. Check the checkbox to select I agree to the terms of service.
(3) Click Login with Salesforce.
(4) In the top menu, hover over utilities and select REST Explorer.
(5) For URI, use the first URI on this page – /services/data/v51.0/jobs/query (where v51.0 is the highest number now)
(6) Select POST for the method and for the Request Body, use the one below
{
“operation”: “query”,
“query”: “Select Id, Lastname from Contact where createdDate > LAST_WEEK”
}

(I added the where clause to achieve my use case because I only want to delete records created recently in the org.
(7) Click Execute
You should get a response like this:

bulkQuery1
Note the queryJobId: 7503h00000AELqVAAX

Monitor the State of the Job

zTo monitor the state of the job:
(1) Create a GET request.
(2) For URI, use /services/data/v51.0/jobs/query/7503h00000AELqVAAX
(where 7503h00000AELqVAAX is the job ID that was returned by the POST request that created the query job )
You get a response that shows the state of the job – JobComplete:

BulkQuery2
Note the number of records processed. Check this to make sure it is the expected number

Get The Result Of The Job

To get the results of the job, create a GET request with the URI below
/services/data/v51.0/jobs/query/7503h00000AELqVAAX/results (replace the jobId with your generated one)
Below is the results

results

Delete the Query Job

Note: Before a job can be deleted, its state should be  JobComplete, Aborted, or Failed.
To delete the query job,
(1) For the method , select DELETE
(2) URI: /services/data/v51.0/jobs/query/7503h00000AELqVAAX
(3) Click Execute, the outcome should be like this:

outcome

Reference

Bulk API 2.0 and Bulk API Developer Guide

Leave a Reply