I am run a batch class from a normal class using Database.executeBatch method, steps below the batch execute methods are executing before the Batch process is completed.

Does there is any way to capture to get the acknowledgment as the batch process is completed.

Below is my code:

ID batchprocessid = Database.executeBatch(new BatchDeleteRcds(), 2000);
AsyncApexJob aaj = [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors FROM AsyncApexJob WHERE ID =: batchprocessid ];
System.debug('Batch processing : '+aaj.NumberOfErrors); 

2 Answers 2


In the finish method you can get your information. Can send some email or something like that.

global void finish(Database.BatchableContext BC){
   // Get the ID of the AsyncApexJob representing this batch job
   // from Database.BatchableContext.
   // Query the AsyncApexJob object to retrieve the current job's information.
   AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
      TotalJobItems, CreatedBy.Email
      FROM AsyncApexJob WHERE Id =
   // Send an email to the Apex job's submitter notifying of job completion.
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {a.CreatedBy.Email};
   mail.setSubject('Apex Sharing Recalculation ' + a.Status);
   ('The batch Apex job processed ' + a.TotalJobItems +
   ' batches with '+ a.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

More help can be found here


Why don't you try to get your final work on onFinish method of the Batch class. Where you can check whether your batch ran successfully or not.

  • can you give me reference where the onFinish method is used in my code.
    – Vivek P
    Aug 4, 2015 at 10:21
  • You have a class "BatchDeleteRcds" which probably implementing Database.Batchable. So in your class i.e. "BatchDeleteRcds" you can write a method 'onFinish(Database.BatchableContext BC)' Aug 4, 2015 at 10:29
  • Use this as a reference developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… Aug 4, 2015 at 10:30
  • do you mean from finish method i need to call the other method of initial Apex class write. if that so, does there is any other approach for this ?
    – Vivek P
    Aug 4, 2015 at 10:40
  • I am saying you can use like this in FINISH method AsyncApexJob aaj = [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors FROM AsyncApexJob WHERE ID =: BC.getJobId() ]; System.debug('Batch processing : '+aaj.NumberOfErrors); Aug 4, 2015 at 10:44

You must log in to answer this question.

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