[SalesForce] Schedule Report In Apex Code

I have a VisualForce page, on it the user chooses when they want the report to run (Daily, Weekly, Monthly). Is there a way to schedule reports to run using Apex code?

Best Answer

I'm with @AdrianLarson here - there's nothing in the metadata api nor analytics api to do this; a given report can only have one schedule, if any, and that is set by the point and click interface

For a user to specify their own unique report schedule, the solutions that come to mind get 'interesting'

Option 1

  • Create a schedulable class that in turn implements logic to retrieve data and display as HTML or CSV. Existing reports could be used via the Analytics API or Apex Analytics classes. Results would be emailed to some recipient list
  • Create a VF page/controller that ultimately sets a CRON expression for the schedulable class as well as a list of recipient emails, then the controller executes the scheduled class. It would run using the running user's profile/ID.
  • Extend the controller to allow for schedules to be viewed and cancelled.

Option2

  • Use an appexchange package like Conga Courier or Conga Composer/Conductor. This isn't too expensive and would have much lower lifecycle costs than trying to build your own custom report scheduler.
  • Conga Courier uses a custom object to define the schedule, report, and recipients; Conga Composer/Conductor does the same but allows multiple reports/queries to be folded into one output file. Output can be CSV, Excel, PDF, Word, Powerpoint and Google Docs
  • You could give the end user direct access to Conga to construct their own schedules or build a simple VF page to front end the Conga interface

In either case, if you have sensitive information in a given report that some recipients can't see but others can, these solutions will be problematic.

Related Topic