+ 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.