レポート実行
Salesforce Reports and Dashboards API via Apex を使用して、同期または非同期にレポートを実行できます。
レポートは、���細の有無に関わらず実行できます。また、レポートメタデータを設定して絞り込むこともできます。レポートを実行すると、Salesforce ユーザーインターフェースでレポートを実行するときに使用できるレコード数と同じ数のレコードのデータが API によって返されます。
すぐにレポートの実行が完了すると期待される場合は、レポートを同期して実行します。それ以外の場合は、次の理由により、Salesforce API を使用して、レポートを非同期に実行することをお勧めします。
-
レポートの実行時間が長い場合、非同期に実行することでタイムアウトの制限に達するリスクが低くなります。
-
Salesforce Reports and Dashboards API via Apex は、一度に多数の非同期実行要求を処理できます。
-
レポートの非同期実行の結果は 24 時間のローリング期間保存されるため、繰り返しアクセスできます。
レポートの同期実行
レポートを同期して実行するには、いずれかの ReportManager.runReport() メソッドを使用します。次に例を示します。
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// Run the report
7Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true);
8System.debug('Synchronous results: ' + results);レポートの非同期実行
レポートを非同期に実行するには、いずれかの ReportManager.runAsyncReport() メソッドを使用します。次に例を示します。
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// Run the report
7Reports.ReportInstance instance = Reports.ReportManager.runAsyncReport(reportId, true);
8System.debug('Asynchronous instance: ' + instance);