1

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?

  • I think it's impossible. – Adrian Larson Feb 17 '16 at 17:57
  • 1
    One could imagine that in conjunction with Conga Courier or Conga Composer/Conductor and appropriate permissions, you could construct records to Conga that would initiate the report schedules per the user's wishes – cropredy Feb 17 '16 at 18:11
  • @crop1645 buy not build eh? – Adrian Larson Feb 17 '16 at 22:54
1

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.

  • You keep agreeing with me lately. :) Props for explaining how you might approach building it. Would you just create a csv attachment? It doesn't seem like it would involve too many LOC...hmm now I'm curious dammit. – Adrian Larson Feb 18 '16 at 2:20
  • 1
    before going too far, check analytics api to make sure you can output reports of more than 2000 rows – cropredy Feb 18 '16 at 2:32
  • Good call. From the docs: "The API returns up to the first 2,000 report rows. You can narrow results using filters." – Adrian Larson Feb 18 '16 at 2:34
  • what I've never figured out is how Conga gets around this limit as they can handle 5000 rows per report – cropredy Feb 18 '16 at 2:36
  • Perhaps they figured out a way to make multiple filtered calls to the API? Might not be too challenging on CreatedDate. Not sure how many times you can hit it in one transaction. – Adrian Larson Feb 18 '16 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.