An Apex utility that demonstrates how to retrieve aggregate-query results in successive batches and emit them as comma-separated debug output for use in a spreadsheet.
The included query identifies duplicate Account records by Name. It is an
example intended to be adapted to the data model and reporting requirement of
the target Salesforce org.
- Runs up to five aggregate-query batches, avoiding the 2,000-row result limit of an individual aggregate query.
- Uses the maximum
CreatedDatereturned by each batch as the next cursor. - Writes CSV-like output to the Salesforce debug log for copying into Excel or another spreadsheet application.
force-app/main/default/classes/AggregateExcelLogger.cls
-
Authorize the target org with the Salesforce CLI.
-
Deploy the source:
sf project deploy start --source-dir force-app --target-org <org-alias>
-
In Execute Anonymous Apex, invoke the utility with an appropriate starting date:
AggregateExcelLogger.logAggregateQuery( DateTime.newInstance(2024, 1, 1, 0, 0, 0) );
-
Open the debug log and copy the comma-separated rows into a spreadsheet.
- Review and tailor
aggregateQuerybefore deployment; it currently queriesAccountrecords and has organization-specific assumptions. - This is a one-time diagnostic/export helper, not a general-purpose reporting service.
- Large result sets can still encounter Apex CPU time or log-size limits. The class comment describes using scheduled executions to split work further.
No license is included. By default, the repository is not granted an open-source license; contact the author to request permission for reuse.