I've been using apex to gather all the info I can from a report. This includes report name, type, filters, fields, date created etc. I also want to see what object its fields belong to.

Take a look at these fields for this report. I know I can manually look up the field name in object manager and find its parent object, but I want to automate that using apex. Any help is appreciated. Thanks.

1 Answer 1


It can be done with a callout to Reports REST API Description:

String reportId = '00O8W0000036obT';

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());

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((String) tmp.get('label') + ' -> ' + (String) tmp.get('entityColumnName') + ' -> ' + ((String) tmp.get('entityColumnName'))?.substringBefore('.')); 
// Company / Account -> Lead.Company -> Lead
  • Wow, that really solved my entire problem. I had been trying to figure this one for days but couldn't get it to work. Thank you so much for your help and quick response.
    – apexdev
    Nov 29, 2021 at 14:52
  • Not at all) If this answer is helpful, please, accept it. @apexdev Nov 30, 2021 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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