OBLYTECH Logo
OBLYTECH Logo

Scheduling Background Work Outside Peak Business Hours

To schedule background Salesforce jobs outside peak hours, pick a window when interactive users are least active, set a rule that says which jobs may start in it and when they must finish, and stagger the start times so jobs do not all launch at once. The mechanism you choose depends on data volume.

Why background work competes with users during business hours

Salesforce is a multitenant platform, so the infrastructure behind your org is shared with other customers. A large data job that runs in the working day draws on the same capacity people use to open records, run reports and save edits. In production, a nightly enrichment run can slow the morning for a sales team trying to work through its queue.

The platform also caps what a single transaction may consume. A job that starts at a busy time has to compete for shared capacity while it runs. A job that starts in a quiet window faces less competition, although its per-transaction limits stay the same.

Two patterns cause much of the trouble when teams schedule jobs. The first is a cluster of jobs that all start at the same minute, usually midnight, because the same default time was picked for each one. The second is a job that starts late in the evening and runs into the first hour of the business day. Planning the windows as a set, rather than choosing a time for each job alone, prevents both.

Pick the window before you schedule anything

Measure when people use the org rather than when you assume they stop. Work through these steps with the owner of each process that runs in the org.

  1. List each background job that will run on a schedule, with the objects it touches, its expected record volume and the time it must finish by.
  2. Note the working hours of each user group. Teams in different regions can share an org with quiet periods that do not line up.
  3. Look at when interactive activity peaks over several weeks, including month-end and quarter-end, since those periods shift the pattern.
  4. Choose a window that begins after the busiest interactive period and ends before the first business day starts in each region you serve.
  5. Test the job in a sandbox that holds data close to production volume. Before that test, work through the release notes review for each sandbox test, because changes in your release can alter how a job behaves.

Set the rule for when a job may run

A window on its own controls nothing. The rule does. Write it down as a short policy that names what may start inside the window and what must stay outside it. A usable rule has four parts:

  • Start window: a fixed span of hours inside the quietest period you measured.
  • Finish deadline: a time before the next business day begins in each region the job affects.
  • Stop condition: what the job does at the window boundary, so a long run pauses or hands off instead of spilling into business hours.
  • Owner and exception path: the person who can change the window, and the approval step for any job that must run during business hours.

Keep the exception list short. A job on that list tends to stay there after its original reason has passed, so review it at each schedule change. For help planning this work, see Salesforce implementation.

Stagger start times so jobs do not spike together

Scheduling a dozen jobs for the same minute recreates the spike you were trying to avoid. Together, the jobs stack their work into one burst. Offset each start time by an amount that fits the expected run time of the job before it. A job expected to run for about forty minutes should not begin when the job that feeds it begins, and the window should leave a gap after the longest job in case a run takes longer than planned.

Before you fix the offsets, check them:

  • Take the expected run time from a test run, not from an estimate.
  • Compare each start time with the others in the same window.
  • Write the offsets into the schedule record, so a later change does not reset them by accident.

Match each job to the right asynchronous mechanism

The schedule answers when a job starts. The mechanism answers how it moves through its records. Asynchronous work is eventually consistent, so its result may not be visible in the transaction that started it. A downstream step that reads that output must run after the upstream job finishes, or it must accept a short delay. Plan that gap into the window. Three mechanisms cover the common cases.

Batch jobs for large record volumes

Batch Apex suits volume. It divides the records into chunks, and each chunk runs with its own governor limits, which makes it the right fit for migrations, archival and bulk enrichment. Overnight runs over large object sets usually belong here. Bulk loads of this kind should be checked against the data loader options for migration before you set the batch size and window.

Queueable jobs for ordered steps

Queueable jobs suit a sequence of steps that exceed synchronous limits but do not need the scale of a batch. A queueable job can chain to another, which keeps dependent steps in order. Use chaining when step two needs the result of step one. Leave independent steps unchained, so one failure does not hold up the rest.

Platform events for decoupled work

Platform events let a producer publish a change that other processes handle later, so the producer does not wait on them. A job that wakes on a timer to look for records that may not exist spends window capacity on nothing. Let the change trigger the work, and keep the scheduled job for work that truly must run on a clock.

Keep each job inside its limits at production volume

Asynchronous jobs run under their own limits, which differ from the limits on synchronous transactions, so moving a heavy step into a background job can be the right fix. Size each job against the limits that apply to the release you run, since they can change between releases.

Design for groups of records rather than one record at a time, because trigger logic receives records in groups. A query or DML statement inside a loop works with a few records and fails at scale. Query the data you need in one statement outside the loop, organize the results into a map keyed by record ID, and process the collection with batched DML.

Test with peak volumes rather than average ones. A job that sits just under a limit on a quiet day can cross it after a spike in records, so build in margin. For a plain-language walk through these ceilings, read the governor limits guide for admins.

Sequence jobs that touch setup and standard objects together

A single transaction that changes setup objects, such as users and permission sets, alongside standard or custom objects can fail with a mixed DML error. Changes that affect a user’s access have to commit in their own transaction. Integration loads, test setup and user provisioning jobs tend to run into this when they are built as one job.

In a schedule, the fix is to split the work. Run the setup change as one job, and start the job for the other records when the first one finishes, using asynchronous processing or a platform event as the hand-off. Give the second job its own start time with enough gap to absorb a slow first run.

Retire scheduled jobs that find no work

A scheduled job that runs when there is nothing to process uses capacity and adds to the load of its window. Review the full schedule each quarter. Criteria worth applying include no executions in the past 90 days, batch jobs that consistently process zero records, and automation that a newer implementation has replaced but nobody has switched off.

Record each deactivation with its reason and date, so the change can be reversed if the business needs the job again. The same logic applies to retention. Archive aged records on a schedule that sits inside a quiet window, so the cleanup does not add to the business day.

Questions about timing and testing background jobs

What if a job has a deadline that falls inside business hours?

Treat it as an exception rather than a default. Add it to the exception list with an owner and the reason it cannot wait. Then ask whether the same result can come from smaller chunks that fit the quiet period, which often makes the exception unnecessary.

How do you judge whether a window is quiet enough?

Compare interactive activity in the candidate window with the busiest parts of the day, using the usage data you can see for the org and feedback from the teams who work in it. A window that looks quiet in a normal week can become busy at month-end, so check the calendar your users follow before you commit.

Can a sandbox run predict the production run time?

A sandbox gives a rough guide. Its data volumes and user activity differ from production. Refresh the sandbox with data close to production size, then add margin for growth before you set the finish deadline. The sandbox refresh planning steps help you time that refresh.

How should a job resume after it stops at the window boundary?

Have the job record where it stopped, such as the last record it completed, and resume from that point when the next window opens. Restarting from the beginning repeats work and can process the same records twice.

Who should own the schedule after the first release?

Name one owner for the schedule record and one person who approves changes to the exception list. Review the schedule when a new job goes in, when user patterns change and at the quarterly review.