[SalesForce] Apex Batch Jobs stop executing unexpectedly

Hi so we have a couple of Apex batch jobs that run continuously in our org. One runs every five minutes and one runs every fifteen minutes. In the batch's finish methods, the two reschedule themselves appropriately. However, the past couple of weeks, the jobs have been randomly not scheduling without warning. The last job to run doesn't have any errors but will not schedule.

job view

The gap in the middle is where we noticed the issue and restarted the job. I'm attempting to enable debug logs but it's difficult without knowing when or why the scheduling doesn't happen.

Messaging_SendMessageBatchScheduler__c msgBatchSchedular = Messaging_SendMessageBatchScheduler__c.getValues('Batch Scheduling Time');
if(msgBatchSchedular != null){
    Integer scheduleTime = Integer.valueOf(msgBatchSchedular.RC_SMS_Status_Batch_ScheduleTime_In_Mins__c);
    if(scheduleTime != null){
            System.scheduleBatch(new Messaging_RCSMSStatusBatch(), 'Check Sent SMS Status Batch', scheduleTime, 70);

That's the finish method.

Best Answer

We have some batch apex jobs that are modeled in the same way. We recently had an issue where the job gut hung. It got stuck in the Scheduled Jobs page but it never made it to the Apex Jobs page (if you know what I mean).

When we chatted with support, they basically said that Scheduled Jobs are not guaranteed to run.

So we wrote some logic now so that if a job gets hung in Scheduled Jobs page (determined by checking whether the Next Scheduled Run date is in the past), we abort the hung job & reschedule it.

We haven't experienced any more hung jobs since. Hope this helps.

Related Topic