I have a batch that runs every minute. In our recent salesforce maintenance window, it stopped running, and has to be restarted manually. This happens occasionally.

Is there a way to monitor is a batch with a certain name hasn't run lately, like "last run time" or something like that?

Ideally, it would be great if we could be alerted if last run time > 5 minutes.

For clarification, there's no error that happens--it's just not being run.

Further Notes:

A batch runs, then its close function schedules the next run in 1 minute. Forever, or until a maintenance window happens :)

  • So you want to be alerted when the job is restarted that the last time a job of the same name was last run more than 5 minutes ago? Nov 4, 2013 at 19:34
  • Keep in mind that scheduled tasks are a shared resources, so the system may feel free to delay it as long as it likes until the resources are free. Perhaps there's a better way to accomplish the task at hand?
    – sfdcfox
    Nov 4, 2013 at 19:48
  • andrew, yes exactly. Nov 8, 2013 at 20:57

1 Answer 1


You must query the CronTrigger object for nextfiretime and previousfiretime and send out an apex email if difference between them is more than 5 min.

  • There are some good examples of the SOQL in this topic, salesforce.com/us/developer/docs/apexcode/Content/…, the PreviousFireTime field should also give the information needed. Perhaps you could work up a small example as part of a revision for your answer? Nov 4, 2013 at 19:44
  • 1
    Combining this with a push topic could be a great way to get the information
    – Matt Lacey
    Nov 5, 2013 at 1:23
  • how do I keep the query going regularly? If it's scheduled apex, what keeps it from stopping on the same events that stops the batch? Nov 8, 2013 at 21:02
  • Query it from an off-platform solution? You could expose a simple web service, getLastRunTime, or something similar.
    – Mike Chale
    Nov 8, 2013 at 21:05
  • All our batch/async stuff is done through the Appleman process now. By using an object to store batch tasks, you get all the fun salesforce features (error logging to fields on the object, dashboard showing all batch stuff by type/date, date field for deferred batches, and best of all, time-based workflow emails for stuff that's sat too long). Jan 6, 2014 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .