Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Return sObject records from a report on a very large object (records>200k)
// Call Schema to get the report metadata
Reports.ReportMetadata reportMd = Reports.ReportManager.describeReport(AnalyticAPISupport__c.getValues('DemoAnalyticAPI').Report_Id__c).getReportMetadata();
//Get the relevant filter in Reports.ReportFilter type variable and set it to the Account Number I'm looking for
Reports.ReportFilter filter = reportMd.getReportFilters()[0];
// Run the report and store the rows in a Reports.ReportFactWithDetail object
// Make sure to use the three parameter version of the Reports.ReportManager class runReport() method to:
// 1. Run the report with the filter we just set and...
// 2. Return a Reports.ReportFactWithDetails object (as opposed to a summary ReportFactWithSummaries object)
Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)Reports.ReportManager.runReport(AnalyticAPISupport__c.getValues('DemoAnalyticAPI').Report_Id__c, reportMd, true).getFactMap().get('T!T');
// Prepare empty array to populate
List<Account> accounts = new List<Account>();
// For each row the report returns, create an Account object and add to our array
for(Reports.ReportDetailRow detailRow : factDetails.getRows())
accounts.add(new Account(Id=Id.ValueOf(String.ValueOf(detailRow.getDataCells()[0].getLabel())),Name=String.ValueOf(detailRow.getDataCells()[1].getLabel())));
// What's in our accounts array?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.