I use getReportMetadata() and after I use getDetailColumns(), but this is list of API Name of columns in the report. I want discover name this columns. Can you help me ?
2 Answers
// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where
DeveloperName = 'abc_Report'];
String reportId = (String)reportList.get(0).get('Id');
// Run a report
Reports.ReportResults results = Reports.ReportManager.runReport(reportId);
// Get the report extended metadata
Reports.ReportExtendedMetadata rmd = results.getReportExtendedMetadata();
// Get detail columns from extended metadata
Map<String,Reports.DetailColumn> colMap = rmd.getDetailColumnInfo();
for(String key : colMap.KeySet()){
System.debug('Key=' + Key + ' label=' + colMap.get(key).getLabel());
}
For more information Refer ReportExtendedMetadata Class
-
That label does not always match up with the report label.– Adrian Larson ♦Commented Oct 27, 2016 at 18:52
-
@AdrianLarson - is this what you were thinking of: for example: a report column labeled
Amount (converted)
in a multi-currency report on Opportunities - such label won't be found in Describe; same for bucket fields– cropredyCommented Oct 27, 2016 at 19:08 -
-
FYI, that is just about the least efficient path you could possibly use to
reportId
.– Adrian Larson ♦Commented Oct 27, 2016 at 20:29
You can describe the report using workbench as described in the Salesforce Reports and Dashboards REST API Developer Guide. The endpoint is simply:
/services/data/<latest API version>/analytics/reports/<report ID>/describe
The data you seek is under reportMetadata
> detailColumns
:
- reportExtendedMetadata
- ...
- reportMetadata
- detailColumns
- ...
- reportTypeMetadata
- ...
Here is a screenshot of a basic Report
I set up on Opportunity
to demonstrate:
And here is the describe information, showing the report labels for these fields: