how to access report filters, programatically

You can only access the report definition via the Metadata API. The Report component type shown here contains the information you need.

This is a Web Service API and not native to Apex. However if you your willing to try it you can use this library built around it to access it from Apex. I've included a demo of it below showing it retrieving a Report definition on a Visualforce page.

enter image description here


I have the exact solution you are looking for, we can do like this:

// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where 
    DeveloperName = 'Company_owned_Independent_sites'];
String reportId = (String)reportList.get(0).get('Id');

 // Run a report
Reports.ReportResults results = Reports.ReportManager.runReport(reportId);

// Get the report metadata
Reports.ReportMetadata rm = results.getReportMetadata();
for(Reports.ReportFilter rf : rm.getreportFilters()){
    system.debug('---col name---'+rf.getcolumn());
    system.debug('---col value---'+rf.getValue());
}

Tags:

Reporting

Apex