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

how to call a single batch class in finish method?





Call a single batch class in finish method:-

global void finish(Database.BatchableContext BC){}

The finish method is called after all batches are processed. Use this method to send confirmation emails or execute post-processing operations.

Each execution of a batch Apex job is considered a discrete transaction. For example, a batch Apex job that contains 1,000 records and is executed without the optional scope parameter from Database.executeBatch is considered five transactions of 200 records each. The Apex governor limits are reset for each transaction. If the first transaction succeeds but the second fails, the database updates made in the first transaction are not rolled back.

Using Database.BatchableContext

All of the methods in the Database.Batchable interface require a reference to a Database.BatchableContext object. Use this object to track the progress of the batch job.

The following is the instance method with the Database.BatchableContext object:

Name Arguments Returns Description

getJobID  ID Returns the ID of the AsyncApexJob object associated with this batch job as a string. Use this method to track the progress of records in the batch job. You can also use this ID with the System.abortJob method.

The following example uses the Database.BatchableContext to query the AsyncApexJob associated with the batch job.

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 });



Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 





   I have a10 batch class , i want to execute the 10 batch  class sequentially after completing the previous one.


        how can i do that?