5

I've been working with Salesforce for over a month now, and in this short time I've learned a lot about the platform. In the process, I've come across situations where the following questions have popped up but on doing a little R&D I wasn't able to find a convincing answer for them. Here are my burning questions:

  1. How many jobs can you schedule at once?
  2. How many unique instances of a class can you schedule at once?
  3. Does the number of unique classes scheduled at a time matter?
  4. In the case of scheduled jobs, how exactly would I check whether I'm over the limit or not?

I know this is a lot to ask, but I'd appreciate the help of any expert or Salesforce developer employee in answering these.

Thanks!

4
  • Probably best to stick to one question per question. Maybe two or three if they're tightly coupled. 7 is an awful lot to squeeze into one answer most of the time.
    – Adrian Larson
    Feb 8, 2017 at 9:46
  • Done. Here's Question 2: salesforce.stackexchange.com/questions/159456/…
    – coldspeed
    Feb 8, 2017 at 9:51
  • Another problem with squeezing multiple questions together is that it becomes very difficult to find a suitable title that is valuable and easy to find later (for the rest of us). If you have a bunch of good questions, it might be best to write them out and space them out one or two per day, and research them in the meantime. Maybe you can answer some of them and share!
    – Adrian Larson
    Feb 8, 2017 at 9:53
  • 1
    Edited. Hope it's better now...
    – coldspeed
    Feb 8, 2017 at 10:02

1 Answer 1

8

Refer to this link for more info on scheduled jobs: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

1. How many jobs can you schedule at once?

You can only have 100 scheduled Apex jobs at one time.

If you exceed 100, ex 101, you will get the following exception:

System.AsyncException: You have exceeded the maximum number (100) of Apex scheduled jobs.

2. How many unique instances of a class can you schedule at once?

The same limit applies here, 100 is the maximum scheduled jobs.

If you currently have 0 scheduled jobs in your org, you can test this yourself with the following code. This will schedule 100 instances of the same scheduled job successfully:

for(Integer i = 0; i < 100; i++){
    MyJob newJob = new MyJob();
    String sch = '0 0 * * * ?'; // every hour every day
    System.Schedule('TEST' + i, sch, newJob);
}

3. Does the number of unique classes scheduled at a time matter?

I suppose it depends on what those jobs are doing. If they are modifying the same data you could have conflicts and locking issues.

4. In the case of scheduled jobs, how exactly would I check whether I'm over the limit or not?

You can evaluate your current count by viewing the Scheduled Jobs page in Salesforce and creating a custom view with a type filter equal to “Scheduled Apex”. You can also programmatically query the CronTrigger and CronJobDetail objects to get the count of Apex scheduled jobs.

Here's how you can find the number of Scheduled Apex in Apex (JobType 7 represents Scheduled Apex):

Integer scheduledJobCount = [SELECT COUNT() FROM CronJobDetail WHERE JobType = '7'];
1
  • 4
    for #4, one should use SELECT COUNT() FROM Crontrigger WHERE cronjobDetail.JobType = '7' and State NOT IN ('DELETED','COMPLETE','ERROR') to avoid counting zombie jobs or jobs that will not execute again
    – cropredy
    Jan 3, 2019 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.