+ Start a Discussion
Jacky LeeJacky Lee 

Apex: Counting the number of groups in queried report data


I have obtained the results of a report using apex. I'd like to retrieve the summary amounts for every record, but unsure how to find out the size, (i.e. count of groups in the report) in order to loop through the report.

According to the guide:
List<Report> reportList = [SELECT Id, DeveloperName FROM Report WHERE Id = 'report ID here'];

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()[0];
System.debug('Key: ' + groupingVal.getKey());		
System.debug('Label: ' + groupingVal.getLabel());

How can I find the size() of dim?

Aggregate Functions will help you ro solve this problem
follow the below link