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
jai raj 6jai raj 6 

.how to get the count of records processed by batch job?


how to  count of records processed by batch job?

Thanks advance.
William TranWilliam Tran
Try setup/monitor/jobs and see if it has what you need.

Thx
SKolakanSKolakan
You can Implement Database.Stateful, count records in execute method and you can get total count in finish method. Here is a sample
 
global class InvoiceBatch implements Database.Batchable<sObject>,Database.Stateful{

   global integer count = 0;

   global Database.QueryLocator start(Database.BatchableContext BC){   
        String query = 'Select Id,Name from Invoice__c';
        return Database.getQueryLocator(query);
   }

    global void execute(Database.BatchableContext BC, List<sObject> scope){
        for(sobject s : scope){
            count++;
            //Process records
        }   
    }

   global void finish(Database.BatchableContext BC){
       System.debug('count:' + count);
   }
}