function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
csbaacsbaa 

Unable to abort Recursive batch job

Hello Helpers


by mistake I  started  recursive  batch class  chain

In the batch  finsih()  method  I  inserted a call for the same batch

Now  I  have a  batc running for  half  day  I  can not stop  it

Abor  does  not work If  i try to abort  I  get the be,ow  message
Failed to Abort Job Unable to remove job from Apex Job Queue.

I  need to stop  this  somehow
What  opton I have?

In the specs  I sew  that  "You can submit up to 5,000 batches per rolling 24 hour period."

but  since start my batch run more then 5000 times    


regards
csaba
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Csbba,

Get Batch job ID from Setup->Monitoring -> Apex Jobs to get batch job ID.

User-added image

and Run below statement from Anonymous block.
System.abortJob(JobID);

Let us know if it helps.
 
SantoshChitalkarSantoshChitalkar
Hi CSABA,

Ashish is correct. Please mark this as solved and choose best answer.

Regards,
Santosh Chitalkar
asadim2asadim2
The answer above is not correct. The question is specifying a chained/recursive batch job. Even with aborting ALL jobs this continues on.

I know this because I am here for the same reason ;)
James WoodwardJames Woodward
It can be difficult to abort a chained job through the UI because the Id keeps changing. Running this anonymous Apex should sort you out.

List<AsyncApexJob> jobs = [SELECT Id, Status FROM AsyncApexJob WHERE Status NOT IN ('Completed', 'Failed')];

for (AsyncApexJob job : jobs)
{
    System.abortJob(job.Id);
}
Carine EloboCarine Elobo
All this didn't work for me.
To solve this issue. I've deleted a class called by the job. 
1542VeMan1542VeMan
I was able to do it finally from the UI. Everytime I tried to abot a job the page would refresh with the Failed to Abort message. But the next Job would appear near the top with the 'Abort' command. Now when you click Abort, a window popups to confirm - just hit the enter key rather than move your mouse up to click it. 
So, you have to keep at it until you catfch one one of them. 
Basically click Abort on each page refresh, then quickly hit the enter key to confirm - and keep doing this until the page refreshes with the Status 'Aborted' on the top line. 
Pramod kumar 185Pramod kumar 185
Hi You can abort Recursive batch job using the following code also.

List<AsyncApexJob> jobs = [SELECT Id, Status FROM AsyncApexJob WHERE Status NOT IN ('Completed', 'Failed','Aborted') limit 150];
for (AsyncApexJob job : jobs)
{
    System.abortJob(job.Id);
}

 
Rick YangRick Yang
For anyone find this topic, try below code. System.abortJob actually works. But your recusive batch might clone itself so fast that one single abort might not shoot. Below code solves my problem

Integer count = 20;
while(true) {
count--;
if(count<0) {
break;
}

List<AsyncApexJob> jobs = [SELECT Id, Status FROM AsyncApexJob WHERE Status NOT IN ('Completed', 'Failed','Aborted') limit 150];
for (AsyncApexJob job : jobs)
{
    System.abortJob(job.Id);
}
}
Avinash Khanwaria 26Avinash Khanwaria 26

Hi Everyone,
The following code worked for me.

List<AsyncApexJob> jobs = [SELECT Id, Status FROM AsyncApexJob WHERE Status NOT IN ('Completed', 'Failed','Aborted') FOR UPDATE];
            for (AsyncApexJob job : jobs)
            {
                System.abortJob(job.Id);
            }

The "FOR UPDATE" keyword locks the record,due to which Apex job is not processed.This will allow the Apex Job to terminate even before executing.

 Mark it as best solution if this works for you too.

Manoj SonawaneManoj Sonawane
It worked well when you abort parent job ID from CronTrigger

List<CronTrigger> jobs = [Select Id, CronJobDetail.Name, State, NextFireTime From CronTrigger limit 10];
for(CronTrigger job : jobs)
{
    System.debug(job);
    System.abortJob(job.Id);
}
Kirtish ShrotriyaKirtish Shrotriya
@Carine Elobo your solution helped me. I tried everthing to abort the jobs but nothing was working. FInally I had to delete that class and and then run the abort job, and it worked. Thank you :D 
Venkata Kunisetty 2Venkata Kunisetty 2
None of the above solutions worked for me but a simple trick did. I deactived the user account running the job.

To do this, you need to login as a different user or ask your colleague to do it for you. 
Nick KovashNick Kovash
None of the solutions worked for me either. I was using the Queueable class to chain jobs within the execute() method. What did work for me was uploading a new version of the Apex Class that commented out the calling of the child job. I had to enable the setting that allowed me to upload an apex class while it has future processes schedule, but after the new class was uploaded and deployed, the queueing stopped.
Meghana Reddy PendyalaMeghana Reddy Pendyala
@Nick Kovash, Can you elaborate your solution?