Code
Apex Class:
global class BatchAccountStateFul implements Database.Batchable<Sobject>, Database.Stateful {
public Decimal AR = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
String query = 'Select Id from Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<SObject> scope) {
for(sobject s :scope) {
AR+=1;
}
}
global void finish(Database.BatchableContext bc) {
Account ac = new Account(Name='Batch Apex Stateful');
ac.AnnualRevenue = AR;
insert ac;
}
}
Apex Code (Execution):
BatchAccountStateFul objA = new BatchAccountStateFul();
Database.executeBatch(objA,10);
Video
Video does not exists.