Thursday, August 29, 2019

Find reports used in a report type in salesforce

It is hard to find the reports for a specific report type. To find the reports for a specific report type we need to customize the report and check the report type name.

Apex has provided a inbuilt functionality to find the report type using the report id.

Execute the below code in anonymous execute window.

for(Report report:[SELECT Id,DeveloperName FROM Report Where NamespacePrefix =null]){
 Reports.ReportDescribeResult results = Reports.ReportManager.describeReport(report.Id);
 Reports.ReportMetadata metadata=results.getReportMetadata();
 Reports.ReportType reportType=metadata.getReportType();
 if(reportType.getLabel() == 'Reporttype Name'){
  System.debug(reportType.getLabel() + '--' + report.DeveloperName);
 }
}