Posts

Showing posts from April, 2020

Salesforce Batch Class for Aggregate Queries

Image
Salesforce Batch Class for Aggregate Queries Recently, I got one requirement, in which I have to use aggregate queries in batch apex class. My requirement was totally different. For blog I'm using Account and Contact as a example. Let us have a walkthrough how to set up Push Notification. Step 1. Create the Notification Route. AggregateResultIterator AggregateResultIterable Implementing to Database.Batchable Iterable start method of Batch Class AggregateResultIterator global class AggregateResultIterator implements Iterator { AggregateResult [] results {get;set;} // tracks which result item is returned Integer index {get; set;} global AggregateResultIterator(String query) { index = 0; results = Database.query(query); } global boolean hasNext(){ return results != null && !results.isEmpty() && index < results.size(); } global AggregateResult next(){ return results[index+