A batch apex class which is scheduled to run daily has been failing lately. It either shows Completed, with 0 total batches (which isn't right if it really ran as expected), or it shows Failed, with an odd error message (just "job xxx failed"). However, if I run it manually (via dev console, using same batch size) it completes as expected.

Here's the apex jobs listing:

enter image description here

The two recent runs showing 7 batches processed are the ones I launched manually. All the others (starting at 6 am) are the failed scheduled runs.

Interestingly, there is also a job shown from much earlier in the year, showing status = Queued. Could that be interfering w/ the scheduled runs somehow? (ignore this)

Any advice on what I should look into here?

  • 1
    Weirdly enough I have this exact same thing happening in my org. I have a ticket open with Salesforce, so I'll let you know what comes of it. Commented Aug 23, 2017 at 21:32
  • @JeffBennett thanks, please do! Do you by any chance have a stuck Queued job like I do here?
    – mscholtz
    Commented Aug 23, 2017 at 21:46
  • I wouldn't say "stuck" per se. As Keith C points out, all "Queued" means is that it's scheduled and awaiting execution, which I would expect if the last job Completed or Failed. Commented Aug 24, 2017 at 13:15
  • Yeah I think that "Queued" job is a red herring. Didn't even notice at first that it's "Scheduled Apex", not "Batch Apex". So I think it's just representation of the active cron trigger.
    – mscholtz
    Commented Aug 24, 2017 at 17:26
  • @JeffBennett nothing yet from your case? We don't have premier support, so I wasn't able to log one.
    – mscholtz
    Commented Aug 25, 2017 at 18:02

3 Answers 3


The view of the screen shot you present is filtered to only show one job. I think you should look at all the jobs that are being run: you might find some correlation between the failures and runs of other jobs that are interfering with this job.

I can't offer anything on the "Failed" ones with nothing helpful in the detail... Open a case with Salesforce?

"Queued" means:

Job is awaiting execution.

whereas "Preparing" means:

The start method of the job has been invoked. This status might last a few minutes depending on the size of the batch of records.

which suggests to me that the stuck job shouldn't be the cause of the problem in the other jobs.

I presume the cases where there was a second run in one day were manual repeats because of the zero records processed by the scheduled job?


Try to utilize finish method and get stack trace to debug.

public void finish(Database.BatchableContext bc){
        AsyncApexJob job = [Select Id, ApexClassID, JobType, MethodName, Status, ExtendedStatus, NumberOfErrors, CompletedDate, JobItemsProcessed,
        TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()];

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {'[email protected]'};
            mail.setSubject('Daily BatchName Job Alert' + job.Status);
            mail.setPlainTextBody('Total batches processed ' + job.TotalJobItems +
           'with '+ job.NumberOfErrors + ' failures.' + '\n' + 'ErrorMessage: \n'+job.ExtendedStatus);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  • can you say why you recommend this? I would guess that it's probably not even reaching the finish method, although I don't know for sure.
    – mscholtz
    Commented Aug 23, 2017 at 21:48
  • if at least one batch wasn't executed we will not enter finish() method (salesforce.stackexchange.com/a/24373/46245). Which could be in your case, you could investigate into start() method. Commented Aug 25, 2017 at 15:42

I have had the same issue on my production org, where was indicated that the job has failed but with no further info. I have opened a ticket with Salesforce and they indicated that it was due to performance issues (one of SOQL queries on the batch class was not efficient/performative in time.

My solution was by indexing one of the fields that was used in query to make the query more efficient.

Hope this helps

You must log in to answer this question.

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