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

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){
            //Process records

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