Category Archives: Analytics API

Scheduled Report Export using Analytics API in Apex

In salesforce we cannot have scheduled email export. Below solution could help to get the scheduled export of the reports as CSV. For this I have used “Execute a Custom Action” feature when we subscribe to email notification. Salesforce has provided feature where Apex code can be executed if the condition specified while subscribing report is met.

Screen Shot 2017-04-08 at 7.11.30 PM

EmailReportExport class

You can use code from : https://gist.github.com/kiran-machhewar/ff0f2ca55b89b793ad88973f7701feb0

In order to get the scheduled export of Report data, report has to be subscribed and while subscribing report select “Execute a Custom Action” and select EmailReportExport class. As per the schedule provided as soon as the conditions are met then execute method from EmailReportExport will get invoked. In the execute method csv data is created by Analytics api in Apex.

Subscribe the report in below way:

Screen Shot 2017-04-08 at 7.47.10 PM

When the condition for the report subscription is met at scheduled time you will get the email notification as in below snapshot:

Screen Shot 2017-04-08 at 7.50.53 PM

Features:

  1. No email limits are consumed since email would be sent to the user who has subscribed the email.
  2. Same EmailReportExport handler can be used with different reports.

Limitation:

Only 2000 records will be available as a csv export.

Happy learning  🙂