在Batch Apex中使用Aggregate SOQL统计查询语句及结果
Class must implement the global interface method: Iterable<AggregateResult> start(Database.BatchableContext) from Database.Batchable<AggregateResult>The following sample code will explain this.
To fix this, using Apex classes that implement Iterator<AggregateResult> and Iterable<AggregateResult> seems the only way for now.
Here is the outline what we should do.
1. Create an Apex class implements Iterator<AggregateResult>.
2. Create an Apex class implements Iterable<AggregateResult>.
3. Implementing to Database.Batchable<AggregateResult>, and Using Iterable
Let’s get started.
Create an Apex class named “AggregateResultIterator” with the following source code :
Create an Apex class named “AggregateResultIterable” with the following source code :
Batch ApexThen implement Batch Apex from Database.Batchable<AggregateResult>, and use Iterable<AggregateResult>, AggregateResultIterable instead of Database.QueryLocator at start execution, as the following source code :
Operation checkRun SampleAggregateBatch and check debug log.
It seems working fine! : )