2

I follow the documentation about filtering a report on a fly and try to get the detail rows by setting

reportMd.setHasDetailRows(true);

however, this doesn't work and the run report results return Reports.ReportFactWithSummaries instead of Reports.ReportFactWithDetails and I can't get the detail rows.

// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where 
    DeveloperName = 'MyReport'];
String reportId = reportList[0].Id;
 
Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId);
Reports.ReportMetadata reportMd = describe.getReportMetadata();
reportMd.getReportFilters()[3].setValue('0061j00000Gg3C2AAJ');

reportMd.getReportFilters().add(new Reports.ReportFilter('OPPORTUNITY_ID', 'equals', '0061j00000Gg3C2AAJ') );
 
reportMd.setHasDetailRows(true);
// Run a report synchronously
Reports.reportResults results = Reports.ReportManager.runReport(reportId, reportMd);

/* Exception at this line since 
run report results return Reports.ReportFactWithSummaries instead of Reports.ReportFactWithDetails

Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails) results.getFactMap().values()[0];
System.debug( factDetails );
*/

1 Answer 1

4

The third parameter includeDetails should be used and set to true for this to happen.

// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where 
    DeveloperName = 'MyReport'];
String reportId = reportList[0].Id;
 
Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId);
Reports.ReportMetadata reportMd = describe.getReportMetadata();
reportMd.getReportFilters()[3].setValue('0061j00000Gg3C2AAJ');

reportMd.getReportFilters().add(new Reports.ReportFilter('OPPORTUNITY_ID', 'equals', '0061j00000Gg3C2AAJ') );
 
// Run a report synchronously
Reports.reportResults results = Reports.ReportManager.runReport(reportId, reportMd, true);
2
  • appreciate the self-answered questions -- you no doubt were stuck for a while, then figured it out and this Q&A benefits the Community
    – cropredy
    May 18, 2021 at 18:58
  • yeah, exactly...
    – Patlatus
    May 19, 2021 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .