Posts

Showing posts with the label Using Aggregate SOQL queries/results in Batch Apex

Using Aggregate SOQL queries/results in Batch Apex

I had created a schedulable batch apex that implements Database.Batchable<sObject> in Salesforce, but if you want to use SOQL having aggregate functions like SUM(), MAX(), COUNT() on results grouped by “GROUP BY” clause in start execution, changing to interface Database.Batchable<AggregateResult> isn’t a workable way, because it fails with the below compile error : Class must implement the global interface method: Iterable<AggregateResult> start(Database.BatchableContext) from Database.Batchable<AggregateResult> The following sample code will explain this. /* * Compile error : Class must implement the global interface method: Iterable<AggregateResult> start(Database.BatchableContext) from Database.Batchable<AggregateResult> */ global class SampleAggregateBatch implements Database.Batchable<AggregateResult> { // The batch job starts global Database.Querylocator start(Database.BatchableContext bc){ String query = 'SELECT COUNT(Id), ...