Alert if a batch process hasn’t run recently

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 🙂

Answer

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.

Attribution
Source : Link , Question Author : Shane McLaughlin , Answer Author : sfdc

Leave a Comment