Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Schedule entry
How-to guide

Set up a Scheduled Apex job for nightly maintenance

Build an Apex class implementing Schedulable, schedule it with a cron expression, and verify it runs on the expected cadence.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 26, 2026

Build an Apex class implementing Schedulable, schedule it with a cron expression, and verify it runs on the expected cadence.

  1. Write the Schedulable class

    Create an Apex class implementing the Schedulable interface. The execute method takes a SchedulableContext and runs your logic (typically calls Database.executeBatch on a Batch Apex class).

  2. Write a unit test

    Test the schedulable class by calling System.schedule inside Test.startTest and Test.stopTest. The test confirms the schedule registers without an exception.

  3. Deploy the class

    Deploy through Salesforce DX, change set, or Developer Console. Confirm Apex Test coverage stays above the 75 percent platform minimum.

  4. Schedule the job

    Open Setup, Apex Classes, click Schedule Apex. Choose the class, set the frequency (Weekly, Monthly, specific cron), and the start time. Save.

  5. Monitor the first run

    Open Setup, Scheduled Jobs. The scheduled job appears with the next run timestamp. After the first run, open Apex Jobs to confirm completion.

  6. Set up failure alerts

    For production jobs, add try/catch logging to the execute method that writes failures to a custom Apex Log object or sends an email to ops. Silent failures are the most common scheduled job incident.

Key options
Scheduled Apexremember

Code-based scheduled execution using the Schedulable interface and a cron expression.

Scheduled Flowremember

Declarative scheduled automation built in Flow Builder; preferred for no-code patterns.

Reporting Snapshotremember

Scheduled job that writes a source report to a target object for historical trend analysis.

Revenue Scheduleremember

Opportunity line item feature that splits revenue across time periods for subscription modeling.

Cron Expressionremember

Time-pattern syntax for fine-grained scheduling in Scheduled Apex.

Gotchas
  • Salesforce caps scheduled Apex jobs at 100 per org. A team that schedules many small jobs hits the cap; consolidate through a master scheduler that dispatches.
  • Cron expressions in Salesforce use seven fields (seconds-minutes-hours-day-month-dayofweek-year). Linux cron uses five; do not paste a Linux cron directly.
  • Scheduled jobs in a paused org still queue but do not execute until the org resumes. After a sandbox refresh, scheduled jobs may need to be re-registered.
  • Revenue Schedule cannot coexist with Quantity Schedule on the same product. Enable one or the other based on how you model subscription revenue.

See the full Schedule entry

Schedule includes the definition, worked example, deep dive, related terms, and a quiz.