レポートの絞り込み
その場で特定の結果を得られるように、API でレポートを絞り込むことができます。
API で行われた検索条件の変更は、ソースレポート定義には影響しません。API を使用して、最大 20 個のカスタム項目検索条件で絞り込みができます。また、検索条件ロジック (AND や OR など) を追加することもできます。ただし、標準検索条件 (範囲など)、行制限による絞り込み、およびクロス条件は使用できません。
レポートを絞り込む前に、メタデータの次の検索条件値を確認しておくと役立ちます。
- ReportTypeColumn.getFilterable メソッドは、項目を絞り込むことができるかどうかを通知します。
- ReportTypeColumn.filterValues メソッドは、項目のすべての検索条件値を返します。
- ReportManager.dataTypeFilterOperatorMap メソッドは、レポートの絞り込みに使用できる項目のデータ型をリストします。
- ReportMetadata.getReportFilters メソッドは、レポートに存在するすべての検索条件をリストします。
レポートの同期実行中または非同期実行中にレポートを絞り込むことができます。
例
レポートを絞り込むには、レポートメタデータの検索条件値を設定してレポートを実行します。次の例では、レポートメタデータを取得して検索条件値を上書きし、レポートを実行します。例:
- ReportMetadata.getReportFilters メソッドを使用して、メタデータからレポート検索条件オブジェクトを取得します。
- ReportFilter.setValue メソッドを使用して、検索条件値を特定の日付に設定し、レポートを実行します。
- 検索条件値を別の日付で上書きし、レポートを再実行します。
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());