
Salesforce’s 100-scheduled-job restrict can sneak up on you when your org scales. You would possibly suppose 100 scheduled jobs feels like lots — till numerous enterprise models want day by day batch runs, month-to-month triggers, specialised reporting duties, and extra. Instantly, you’re caught making an attempt to determine the right way to add extra time-based processes with out hitting that cap.
To deal with this, I designed a dynamic scheduling framework that consolidates a number of jobs into only one. As a substitute of scheduling each single job individually, we depend on {custom} settings to instruct a “grasp” scheduled job which duties to run and when.
The place the Drawback Begins
Think about a typical situation in a rising Salesforce group:
- The accounting division needs day by day billing processes.
- The gross sales workforce schedules lead cleanup duties each morning.
- Advertising has weekly information export runs.
Every job will get its personal scheduled class, and fairly quickly, your org is crowded with scheduled jobs that collectively exceed the 100-job restrict.
The Dynamic Scheduling Framework
The concept is straightforward: As a substitute of scheduling 50+ jobs, you schedule one grasp job. That single job seems at custom-setting information that specify which jobs to run at what instances. This fashion, you stay effectively inside Salesforce’s scheduling restrict.
1. Customized Settings for Job Data
As a substitute of counting on a number of scheduled jobs that shortly bump you into Salesforce’s 100-job restrict, we use a single {custom} setting containing a number of job information. Every document has the next key fields:
- Lively (Checkbox) – Signifies whether or not this explicit job must be run in any respect. Solely energetic jobs are processed.
- Class Identify – The title of the Apex class if the job is a Batch, Queueable, or Schedulable.
- Move API Identify – If the job runs a move, this area captures its API title.
- Minute Interval, Hour Interval, Day Interval – Decide how often (in minutes, hours, or days) the job ought to run.
- Begin Time – When to start scheduling this job.
- Final Run – The final time the job was truly executed.
- Final Run Standing – A fast standing indicator (e.g., “Success” or “Failed”).
- Final Run Exception – Captures any error message if the final run fails.
These fields allow you to handle your complete schedule and execution logic with out altering your code — simply replace or add information as wanted.
2. The “Grasp Job”
Quite than scheduling every job individually, schedule one “grasp job” to run at a brief interval (generally each 5 minutes). Right here’s what it does:
- Fetch energetic jobs
- Queries all of the {custom} settings information the place
Lively = true
.
- Queries all of the {custom} settings information the place
- Test timing
- For every document, the grasp job seems at
LastRun
and compares it with the present time plus the configured intervals (minute interval, hour interval, or day interval). - If it’s time to run (i.e., now could be better than or equal to
LastRun + Interval
), the grasp job triggers that particular job.
- For every document, the grasp job seems at
- Replace LastRun
- After executing the job, the grasp job updates the document with the brand new
LastRun
, together with any ensuing standing or exceptions.
- After executing the job, the grasp job updates the document with the brand new
Because of this centralized logic, your org at all times stays effectively beneath the scheduled job restrict.
3. Executing the Proper Apex (or Move)
Each job could possibly be one in all a number of varieties — Move, Schedulable Apex, Batch Apex, or Queueable Apex. The grasp job checks your {custom} setting document to see:
- If Move API title is populated:
- The grasp job runs the corresponding Move utilizing its API title.
- If Class Identify is populated:
- The grasp job instantiates and executes the indicated class.
- It checks if the category implements Schedulable, Batchable, or Queueable and calls the proper technique accordingly.
By doing this dynamically, you may simply add or take away totally different job varieties with out writing a bunch of recent code — simply plug within the title or API reference within the {custom} setting.
Instance Move
- Grasp job kicks off (each 5 minutes)
- It’s 12:00 PM; the grasp job begins.
- Question the {custom} setting
- Finds all energetic jobs and compares
LastRun + (Minute/Hour/Day interval)
with the present time. - Let’s say a document known as
Daily_LeadCleanup
has an hour interval of 24 hours and aLastRun
of 12:00 PM yesterday. Immediately at 12:00 PM, it’s on account of run once more.
- Finds all energetic jobs and compares
- Execution
- The grasp job notices
Class Identify = “DailyLeadCleanupBatch”
. - It runs
Database.executeBatch
(newDailyLeadCleanupBatch()
).
- The grasp job notices
- Replace document
- As soon as the job completes, the grasp updates
LastRun
to 12:00 PM at the moment. - If it fails,
Final Run Standing = “Failed”
andFinal Run Exception
accommodates the error. In any other case,Final Run Standing = “Success”
.
- As soon as the job completes, the grasp updates
- Subsequent cycle
- At 12:05 PM, the grasp job begins once more.
Daily_LeadCleanup
gained’t run now as a result of its subsequent run time is 12:00 PM tomorrow. However different jobs may be due, relying on their intervals.
- At 12:05 PM, the grasp job begins once more.
Why This Works So Effectively
- No 100-job restrict. Just one grasp job is definitely scheduled; it orchestrates every part else.
- Versatile intervals. Every job can have its personal minute/hour/day intervals with out messing up the schedule.
- Simple upkeep. Flip jobs on or off by toggling Lively. Tweak intervals just by updating document fields.
- Unified error monitoring. Logging exceptions and statuses in
Final Run Standing
andFinal Run Exception
makes troubleshooting simpler. - Scalable. As your org grows, including extra duties is just a matter of making new custom-setting information.
Conclusion
With this method, you flip Salesforce’s scheduling constraints right into a centralized, metadata-driven answer. One grasp job checks your {custom} setting each 5 minutes (or no matter interval you select) and executes whichever duties are due. In case you’ve ever been pissed off by hitting the 100-scheduled-job ceiling, this framework gives an easy, sustainable option to preserve your org’s automated processes buzzing.