Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Get Report Metadata
You can retrieve report metadata to get information about
a report and its report type.
Metadata includes information about fields that are used in the
report for filters, groupings, detailed data, and summaries. You can
use the metadata to do several things:
- Find out what fields and values you can filter on in the report type.
- Build custom chart visualizations by using the metadata information on fields, groupings, detailed data, and summaries.
- Change filters in the report metadata when you run a report.
Use the ReportResults.getReportMetadata method to retrieve report metadata. You can then use the “get” methods on the ReportMetadata class to access metadata values.
Example
The following example retrieves metadata for a report.
1// Get the report ID
2List <Report> reportList = [SELECT Id,DeveloperName FROM Report where
3 DeveloperName = 'Closed_Sales_This_Quarter'];
4String reportId = (String)reportList.get(0).get('Id');
5
6// Run a report
7Reports.ReportResults results = Reports.ReportManager.runReport(reportId);
8
9// Get the report metadata
10Reports.ReportMetadata rm = results.getReportMetadata();
11System.debug('Name: ' + rm.getName());
12System.debug('ID: ' + rm.getId());
13System.debug('Currency code: ' + rm.getCurrencyCode());
14System.debug('Developer name: ' + rm.getDeveloperName());
15
16// Get grouping info for first grouping
17Reports.GroupingInfo gInfo = rm.getGroupingsDown()[0];
18System.debug('Grouping name: ' + gInfo.getName());
19System.debug('Grouping sort order: ' + gInfo.getSortOrder());
20System.debug('Grouping date granularity: ' + gInfo.getDateGranularity());
21
22// Get aggregates
23System.debug('First aggregate: ' + rm.getAggregates()[0]);
24System.debug('Second aggregate: ' + rm.getAggregates()[1]);
25
26// Get detail columns
27System.debug('Detail columns: ' + rm.getDetailColumns());
28
29// Get report format
30System.debug('Report format: ' + rm.getReportFormat());