Quickly Abort Bulk API Jobs
The Problem
Aborting Bulk API V2 jobs can be done via API, but do it from the Salesforce UI requires clicking into each and every job and clicking the Abort button, which is very time consuming if there are a lot of them.
A Semi-Automated Approach
First off you need your session ID, this can be obtained from the developer console by running this in Execute Anonymous:
Assert.areEqual('', UserInfo.getSessionId());
If you simply try to log the value with System.Debug()
it'll be redacted, but doing this will pop-up a dialog box for the failed assertion, conveniently showing you the value.
Next open the bulk API jobs page, open the JS developer console, and run this code (replacing <<session ID>>
with the ID you previously obtained):
document.querySelectorAll('a[href^="/750P"]').forEach(a => {
fetch('services/data/v60.0/jobs/ingest/' + a.innerText, {
"headers":
{
"Authorization": "Bearer <<session ID>>",
"Content-Type": "application/json"
},
"method": "PATCH",
"body": '{ "state" : "Aborted" }'
});
});
If you need to cancel a lot of jobs, you can open the iframe for the jobs list in a new tab, and just the rowsperpage
parameter in the URL, increasing it to a much higher number.