enter image description hereI have a report that has more than 1 grouping level but i only need the data from the first grouping level of each row returned. I have 125 rows for the first grouping level, i only want that data.

How can i get my data in apex from that report?

here is the code i used so far

List <Report> reportList = [SELECT Id,DeveloperName FROM Report where Id = '00O1p000005Ciol'];
String reportId = (String)reportList.get(0).get('Id');

Reports.reportResults results = Reports.ReportManager.runReport(reportId, true);

Reports.Dimension dim = results.getGroupingsDown();
Reports.GroupingValue groupingVal = dim.getGroupings()[1];
System.debug('Key: ' + groupingVal.getKey());
System.debug('Label: ' + groupingVal.getLabel());
System.debug('Value: ' + groupingVal.getValue());

String factMapKey = groupingVal.getKey() + '!T';
Reports.ReportFactWithDetails factDetails =(Reports.ReportFactWithDetails)results.getFactMap().get(factMapKey);

Reports.SummaryValue sumVal = factDetails.getAggregates()[0];
System.debug('Summary Value: ' + sumVal.getLabel());

Reports.SummaryValue sumVal1 = factDetails.getAggregates()[1];
System.debug('Summary Value1: ' + sumVal1.getLabel());

In the image, the row that has yellow highlighted part is the grouping level that i want to only get BUT with the code above, it gets everything including the sub groups and i only need the yellow parts not the red circles.

  • what have you tried so far ? – Oleksandr Berehovskyi Jun 6 '19 at 7:18
  • @Oleksandr Berehovskyi - i have edited my question. that is the code i used to try it out – user69477 Jun 6 '19 at 7:48
  • @Oleksandr Berehovskyi – user69477 Jun 6 '19 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.