+ Start a Discussion
Marry SteinMarry Stein 

Run reports in apex VS Soql

Hello folks,
I recently came across the method of accessing report data via Apex. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_analytics_report_data.htm

I find the method very interesting for a current use case. I could either access one or more reports directly and use the aggregations or go the usual way via a soql query.

Do you have an opinion on this? Do you already use the method and can you name the advantages?

Thank you very much and have a nice day,
M
 
PriyaPriya (Salesforce Developers) 

Hi Marry,

You can run a report synchronously or asynchronously through the Salesforce Reports and Dashboards API via Apex.
Reports can be run with or without details and can be filtered by setting report metadata. When you run a report, the API returns data for the same number of records that are available when the report is run in the Salesforce user interface.
Run a report synchronously if you expect it to finish running quickly. Otherwise, we recommend that you run reports through the Salesforce API asynchronously for these reasons:
- Long-running reports have a lower risk of reaching the timeout limit when they are run asynchronously.
- The two-minute overall Salesforce API timeout limit doesn’t apply to asynchronous runs.
- The Salesforce Reports and Dashboards API via Apex can handle a higher number of asynchronous run requests at a time.
- Because the results of an asynchronously run report are stored for a 24-hour rolling period, they’re available for recurring access.

 

For more information refer this article :- 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_analytics_run_reports.htm

 

Please mark it as the Best Answer so that it can help others in the future.

Regards,

Priya Ranjan