7

Is there a way to delete an AsyncApexJob with Queued status ?

I can't do it in the Setup because I don't have any action link available for this jobs.

I can't do it with the purgeOldAsyncJobs() method because it doesn't clear jobs with this status.

And I can't do it with Developer console because after listing this jobs, if I try to delete them I got this error message :

[object Object]: insufficient access rights on object id

I'm connected as System Administrator.

Any ideas to do this ?

0

2 Answers 2

7

If it's queued that implies its scheduled, therefore you should be able to get the Job ID and abort it, e.g.

System.abortJob(jobId);
0
13

In case Phil's solution doesn't work, and you are stuck with a zombie Queued AsyncApexJob, here's a workaround:


At Version 39.0, an attempt to delete a zombie Queued AsyncApexJob that has no associated CronTrigger using

System.abortJob(theAsyncApexJobId)

fails with:

System.StringException: You can’t abort scheduled Apex jobs by calling System.abortJob with an AsyncApexJob ID. Call System.abortJob with the parent CronTrigger ID

But, if you go into Workbench and downgrade to Version 31.0 (other versions may work as well)

and execute

System.abortJob(theAsyncApexJobId)

It works! and the AsyncApexJob's status is switched to Aborted.

This is a huge plus especially for developers without Premier Support who otherwise might not get any SFDC assistance on this issue in a sandbox or DE.

2
  • @PhilHawthorn - I tried your solution (v39), which killed the CronTrigger but left the AsyncApexJob as a zombie. Not sure why.
    – cropredy
    Commented May 6, 2017 at 1:36
  • 1
    you need to go back to v31. I just confirmed this is working Commented Aug 22, 2023 at 18:16

You must log in to answer this question.

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