Apex Batch Class Base
global class BatchExample implements Database.Batchable<sObject>, Database.Stateful {
// instance member to retain state across transactions
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'query'
);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
// process each batch of records
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed!');
}
}