Skip to main content

SF-0394 · Scenario · Medium

When should we use scheduled apex?

✓ Verified by Vikas Singhal · Last reviewed 5/17/2026 · Updated for Spring '26

Use Scheduled Apex whenever you need code to run on a recurring time-based schedule — independent of any user action or data event. The classic use cases all involve “run this every N minutes/hours/days”:

Use caseSchedule
Auto-close stale CasesDaily at 2 AM
Sync data to/from external systemEvery 15 minutes
Generate and email weekly reportsMonday 6 AM
Reset rolling metricsSunday midnight
Process records flagged for delayed actionHourly
Send reminder notificationsDaily
Run health checks on dataDaily
Trigger a long Batch Apex job overnightNightly

When Scheduled Apex is the right tool

  • Time-based, not event-based. Something runs because the clock said so, not because a record changed.
  • Predictable cadence. “Every Monday at 6 AM” is exactly what cron expressions handle well.
  • Independent of user action. Nobody clicks anything to trigger it.

When something else is better

NeedBetter than Scheduled Apex
Process a record when it changesTrigger / Flow
Defer a single async task once@future or Queueable
Process millions of records in chunksBatch Apex (schedule the invocation with Scheduled Apex)
Run code in response to an outbound eventPlatform Event subscriber
Trigger UI refreshStream API or Lightning Realtime

Scheduled Apex is rarely the processing engine. More often it’s the trigger that fires off a Batch Apex or Queueable job at the right time. This is the most common production pattern:

public class NightlyCleanupSchedule implements Schedulable {
    public void execute(SchedulableContext ctx) {
        Database.executeBatch(new StaleCaseCloserBatch(), 200);
    }
}

// Schedule once:
System.schedule('Nightly Cleanup', '0 0 2 * * ?', new NightlyCleanupSchedule());

The Schedulable fires nightly; the work is done in the Batch job it kicks off.

When NOT to use Scheduled Apex

Anti-patternWhy bad
Polling for records that changedUse triggers / Platform Events instead
Running every minute to “stay alive”Inefficient; revisit the design
Calling out to an external API in executeScheduled execute doesn’t allow direct callouts (use Queueable)
Doing heavy DML directly in executeLimited to one-transaction governor limits; use Batch instead

Practical thresholds

Volume / cadenceTool
< 100 records, every hourScheduled Apex with logic in execute
100–10,000 records, every hourScheduled Apex that kicks off a Queueable
> 10,000 recordsScheduled Apex that kicks off Batch Apex
Continuous streamingPlatform Events subscriber, not Scheduled Apex

Common interview follow-ups

  • Can you do callouts directly in Scheduled Apex? — No. Use a Queueable from execute.
  • Is Scheduled Apex synchronous or async? — Async — fires from the scheduler service.
  • How many Schedulable jobs can be active? — 100.
  • Can a Schedulable schedule itself? — Yes, but tread carefully — easy to create runaway schedules.

Verified against: Apex Developer Guide — Scheduled Apex Overview. Last reviewed 2026-05-17.