Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Filter Reports
Changes to filters that are made through the API don’t affect the source report definition. Using the API, you can filter with up to 20 custom field filters and add filter logic (such as AND and OR). But standard filters (such as range), filtering by row limit, and cross filters are unavailable.
Before you filter a report, it’s helpful to check the following filter values in the metadata.
- The ReportTypeColumn.getFilterable method tells you whether a field can be filtered.
- The ReportTypeColumn.filterValues method returns all filter values for a field.
- The ReportManager.dataTypeFilterOperatorMap method lists the field data types that you can use to filter the report.
- The ReportMetadata.getReportFilters method lists all filters that exist in the report.
You can filter reports during synchronous or asynchronous report runs.
Example
- Retrieves the report filter object from the metadata by using the ReportMetadata.getReportFilters method.
- Sets the value in the filter to a specific date by using the ReportFilter.setValue method and runs the report.
- Overrides the filter value to a different date and runs the report again.
1// Get the report ID
2List <Report> reportList = [SELECT Id,DeveloperName FROM Report where
3 DeveloperName = 'Closed_Sales_This_Quarter'];
4String reportId = (String)reportList.get(0).get('Id');
5
6// Get the report metadata
7Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId);
8Reports.ReportMetadata reportMd = describe.getReportMetadata();
9
10// Override filter and run report
11Reports.ReportFilter filter = reportMd.getReportFilters()[0];
12filter.setValue('2013-11-01');
13Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd);
14Reports.ReportFactWithSummaries factSum =
15 (Reports.ReportFactWithSummaries)results.getFactMap().get('T!T');
16System.debug('Value for November: ' + factSum.getAggregates()[0].getLabel());
17
18// Override filter and run report
19filter = reportMd.getReportFilters()[0];
20filter.setValue('2013-10-01');
21results = Reports.ReportManager.runReport(reportId, reportMd);
22factSum = (Reports.ReportFactWithSummaries)results.getFactMap().get('T!T');
23System.debug('Value for October: ' + factSum.getAggregates()[0].getLabel());