9

I want to get the api name of the standard field being used in Reports of Standard report types. I used describe methods to get the columns used in a report. I analysed some of standard reports containing standard fields(of both standard and custom objects).

I found that Names of those field are not same as API name of the field. For example, For Opportunity's Name I got three names in some of standard reports of Standard report types. These are: OPP_NAME, OPPORTUNITY_NAME, OPP.NAME.

Is there any mapping or something in apex using which i can get the exact field name used in report?

1
  • Chiming in that I'd like to get an answer to this one, as well. Feb 6, 2020 at 22:59

1 Answer 1

2

A bit late answer, but hopefully useful.

Cutting short, yes, there is a way. However, I couldn't find, how to do it without callout to Reports REST API Description.

String reportId = '00O63000001NtWU';

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v51.0/analytics/reports/' + reportId + '/describe');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setMethod('GET');

HttpResponse res = http.send(req);
Map<String, Object> resBody = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
Map<String, Object> reportExtendedMetadata = (Map<String, Object>) resBody.get('reportExtendedMetadata');
Map<String, Object> detailColumnInfo = (Map<String, Object>) reportExtendedMetadata.get('detailColumnInfo');
for (String key : detailColumnInfo.keySet()) {
    Map<String, Object> tmp = (Map<String, Object>) detailColumnInfo.get(key);
    System.debug(key + ' ' + (String) tmp.get('entityColumnName')); // OPPORTUNITY_NAME Opportunity.Name
}

I have also tried to retrieve reportExtendedMetadata without callout, but it has less information in detailColumnInfo (the core thing it has NO entityColumnName info):

String reportId = '00O63000001NtWU';
Reports.reportResults body = Reports.ReportManager.runReport(reportId, true);
Reports.ReportExtendedMetadata reportExtendedMetadata = body.getReportExtendedMetadata();
Map<String, Reports.DetailColumn> detailColumnInfo = reportExtendedMetadata.getDetailColumnInfo();

for (String key : detailColumnInfo.keySet()) {
    System.debug(detailColumnInfo.get(key).getName()); // no information about entityColumnName
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.