2

I wrote a batch class and called same batch class from finish method without any time interval, Now I am not able to stop it..

global class SaveFileIntoDropbox implements Database.Batchable<sObject>,Database.AllowsCallouts{

  global Database.QueryLocator start(Database.BatchableContext BC) {
        string soql = 'select id from ContentVersion';
        return Database.getQueryLocator(soql);
  }
  global void execute(Database.BatchableContext BC, list<sObject> scope) {
        ....
  }
  global void finish(Database.BatchableContext BC) {
    Database.executeBatch(new SaveFileIntoDropbox(),1);
  }
}

Update I already tried:

string a = [Select a.Name, a.Id From ApexClass a where a.Name like 'save%'].id;
List<AsyncApexJob> lstJobs = [SELECT Id FROM AsyncApexJob WHERE ApexClassID=:a and status != 'completed' ]; 
system.debug(lstJobs.size());
for(AsyncApexJob job : lstJobs) {
   try {
      System.abortJob(job.Id); //01p0k000001ZyIGAAS
   } catch(Exception ex ) {
      System.debug(ex);
   }
}
3
  • 3
    Perhaps you can use the System.abortJob in Developer Console to get rid of it? See this post for some info on how salesforce.stackexchange.com/questions/80714/… – Phil Hawthorn Jan 24 '20 at 5:52
  • I already tried it But no use – nubie Jan 24 '20 at 7:12
  • I believe abortJob will work as long as a) you have permission and b) you use apex to find the job ID by query and pass that to the system call (if you do this manually it seems likely the job could have already finished by the time you execute the command) – Phil W Jan 24 '20 at 7:24
3

If System.abortJob is not working for you, make sure you update the Deployment Settings on the org allowing updates to Apex that has pending jobs, edit the batch to remove the chaining and re-deploy (or edit via setup) your batch code. It will then stop once the current instance has finished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.