I've noticed some strange behaviour in an org which I've not seen before regarding Apex Jobs.

It seems all batch jobs, which are started by a scheduled apex job, never run straight away and are always placed into the Apex Flex Queue in a "Holding" state and are only started once another job is added to the queue.

This behaviour means that if we have 2 scheduled batch apex jobs, one set to run daily at 03:00 (Batch A) and another daily at 04:00 (Batch B), Batch A is held from 03:00 until 04:00 when it then runs (because Batch B is added), but the Batch B then won't run until 03:00 the next day, 23 hours later, because Batch A has started again.

To get around this, as a temporary measure, I've created 4 new hourly batch jobs (running at ?:01, ?:16, ?:31 & ?:46) to ensure the jobs get processed more frequently.

From the Flex Queue Docs:

You can place up to 100 batch jobs in a holding status for future execution. When system resources become available, the jobs are taken from the top of the Apex flex queue and moved to the batch job queue. Up to five queued or active jobs can be processed simultaneously for each org.

This would imply that system resource isn't available, but how could that be if when the next job is started, it seems to force/allow the last job to start running, even though no other jobs are currently running in the background.

All the jobs are being executed using:

Database.executeBatch(new ThisIsMyApexBatchClass());

Any insight into why this is happening would be appreciated, since I believe this to be a problem on the platform, and previous efforts to get help from Salesforce Support are proving fruitless, and just directing us to the forums.



2 Answers 2


In case anyone else ever has this problem in the future, you have to contact Salesforce support and (if you don't have Premier Support because you can't submit Apex issues) convince the agent to escalate this for you, explaining you need to remove any ApexToken jobs which are stuck in the queue. These are visible through a query, but not in the UI, and we (users) can't remove them.

SELECT Id, JobType, CreatedDate, Status FROM AsyncApexJob WHERE JobType = 'ApexToken'

Once this was done, the jobs started as expected.

There was a developer forums post which helped identify this issue: https://developer.salesforce.com/forums/?id=9060G000000I4EzQAK

For those looking for the solution to Sara's issue (not the other issue introduced later in the thread), here's a way to get this fixed. If you don't have Developer Support due to subscription level, your first battle will be to convince the Email & Desktop Integrations team that this is a known SF issue and needs to be handled by Dev Support anyway. They will attempt to close the case and refer you to this forum.

Once it's at Dev Support, you'll need to get this escalated to Tier 3 Dev Support, this isn't so much a challenge as it is time-consuming. Once it gets there, you should get it resolved. I recommend getting on the phone with a supervisor as soon as you submit your case, explain the situation and appeal to their common sense to have a Tier 3 Support tech go straight to the fix instead of walking through all the normal troubleshooting steps at all Tiers, which will prove pointless.

Refer to this forum post (https://developer.salesforce.com/forums/ForumsMain?id=9060G000000I4EzQAK) and include the following, or something similar, in your case description to supplement your other info:

Please review Case 15876990 which details the same problem I'm having, but with another customer. SF Tier 3 Developer Support can easily fix this when they look for and remove any Apex Token jobs stuck in queue, caused by a SalesForce platform bug. One SF tech that has fixed this is Varun Guruvugari, Success Agent - Tier 3.

This is NOT a developer issue. It is a functionality/operational issue. I'm not asking for support to build anything. The fix is only under your control. I understand why you restrict Developer Support to certain subscription levels. However, when it's the platform that should run the job and isn't doing it, as is the case with this issue, that must be something that should be looked at for any customer that has the capability to run jobs, regardless of subscription level.

The job stopped being run and since we don't develop anything, the package being run hasn't changed (its managed). This is something for Salesforce to fix.


I am not sure If I am facing same issue. I am not an SF developer but I am trying to identify root of performance issue. We have Third party integrated with Salesforce and it brings in data every day nightly process and also real time. We had 1 month lag in processing. When I try to dig into the backend, I found out there are batch processing happening every few seconds with batch size 1. Every batch running 4-5 secs Which is lot of time for size 1. I always see job always quequed in Flex Queque though only one job processing. There are 49 other scheduled Apex job quequed too.

when I queried using your above Soql . I saw one "ApexToken" in "queque" status since 10 months. Do you thing "ApexToken" is causing performance issue and we need to delete it?

  • add to it.. there always one job in processing.. only one job in holding in flex queque. 49 other scheduled jobs in queque status Commented Jul 15, 2018 at 2:47
  • Sounds like you have a problem like mine. As soon as support deleted the apextoken type record, everything worked as expected. Commented Jul 17, 2018 at 16:07

You must log in to answer this question.

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