function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jacky LeeJacky Lee 

Apex: Counting the number of groups in queried report data

Hi,

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?

Thanks
ashishashish
hi,
Aggregate Functions will help you ro solve this problem
follow the below link
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_agg_fns.htm