Keep counts across Batch transactions
start, each execute and finish run in separate transactions.
Your task
Make the Batch class stateful so finish can report how many Accounts execute reviewed and how many it skipped.
public class AS_200B77ADA6CA_StatefulReviewBatch implements Database.Batchable<SObject> {
private Set<Id> accountIds;
private Id summaryId;
private Integer reviewedCount = 0;
private Integer skippedCount = 0;
public AS_200B77ADA6CA_StatefulReviewBatch(Set<Id> accountIds, Id summaryId) {
this.accountIds = accountIds;
this.summaryId = summaryId;
}
public Database.QueryLocator start(Database.BatchableContext context) {
return Database.getQueryLocator([
SELECT Id, Description
FROM Account
WHERE Id IN :accountIds
]);
}
public void execute(Database.BatchableContext context, List<SObject> scope) {
}
public void finish(Database.BatchableContext context) {
}
}Requirements
- reviewsSelectedAccounts should pass
- countsReviewedInFinish should pass
- countsSkippedAccounts should pass
- reportsZeroForNoRows should pass
- keepsCountsPerJob should pass