Scheduling jobs through cron expressions in Salesforce sounds like a simple task until you actually do it.
Seeing that cron expression syntax almost felt like stumbling upon an ancient programming language.
Those asterisks and question marks are more like an encrypted message than actual code.
But things change when you slowly get a grip on them. They become your ticket to automating hundreds of business processes.
If you want to clean up old records every night at 1 AM, or sync monthly data. You can do it with a cron expression.
This guide will break down scheduling Apex jobs in Salesforce in a simple, digestible way. So let’s get started.
What Are Cron Expressions in Salesforce?
Let understand it in this way, when you want to remember something in your day-to-day life, you put a reminder on your phone or watch.
Exactly, in the same way cron expressions work as a reminder for Salesforce. It tells Salesforce to run a piece of code at a particular time and day without your intervention.
Cron expressions work as strings of characters that define precisely when your Apex code should execute. The beauty is that once you set them up, they run automatically in the background.
In Salesforce, use cron expressions with the System.schedule() method to trigger classes that implement the Schedulable interface.
Cron Expression Syntax
A Salesforce cron expression has seven fields, each separated by a space:
Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year
The following are the values for the expression:
| Name | Value |
|---|---|
| Seconds | 0–59 |
| Minutes | 0-59 |
| Hours | 0-23 |
| Day_of_month | 1-31 |
| Month | 1-12 |
| Day_of_week | 1-7 |
| optional_year | null or 1970–2099 |
What do Special Characters Mean in Cron Expression?
- * = “all values” or “every.”
- ? = “no specific value” (used in either day-of-month OR day-of-week, never both)
- – = ranges (example: 9-17 for business hours)
- , = multiple values (example: MON, WED, FRI)
- / = increments (example: 0/15 = every 15 units)
- L = “last” (last day of month, last Friday, etc.)
- W = nearest weekday to a given date
- # = nth occurrence (example: FRI#3 = third Friday)
Cron Expression Salesforce Examples
| Expression | Description |
|---|---|
| 0 0 0 ? * * * | at 12:00 AM every day |
| 0 0 10 ? * * | at 10.00 AM every day |
| 0 0 10 * * ? | at 10.00 AM every day |
| 0 0 10 * * ? * | at 10.00 AM every day |
| 0 0 15 ? * * * | at 3:00 PM every day |
| 0 0-5 15 * * ? | Every minute starting at 3:00 PM and ending at 3:05 PM, every day |
| 0 15 17 ? * MON-FRI | at 5:15 PM every Monday, Tuesday, Wednesday, Thursday and Friday |
| 0 15 10 15 * ? | at 5:15 PM on the 15th day of every month |
| 0 15 17 ? * 6#3 | at 5:15 PM on the third Friday of every month |
| 0 0 18 ? * 6L | runs the last Friday of every month at 6:00 PM. |
| ‘0 30 * * * *’; | every 30 minutes |
| 0 0 12 * * ? | at 12:00 PM every day |
| 0 0 23 * * ? 2016 | runs every day at 11:00 PM during the year 2016. |
How to Schedule a Cron Job in Apex
To run a scheduled job in Salesforce, you first create a class that tells Salesforce what should happen when the job runs. You need three things:
- An Apex class that implements the Schedulable interface.
- A cron expression that defines the schedule.
- The System.schedule() method to tie it all together.
You can find the basic structure given below:
public class MyScheduledJob implements Schedulable {
public void execute(SchedulableContext context) {
// Your code goes here
// This is what runs on schedule
}
}
This class runs the code inside the execute method whenever the schedule triggers.
Next, you schedule the job using a cron expression:
MyScheduledJob job = new MyScheduledJob(); String cronExpression = '0 0 2 * * ?'; // Runs at 2 AM daily String jobName = 'Nightly Data Cleanup'; System.schedule(jobName, cronExpression, job);
This example schedules the job to run every day at 2 AM.
Once scheduled, Salesforce saves it as a job record that you can view or manage from Setup → Scheduled Jobs.
Final Thoughts
Cron expressions in Salesforce are crucial when your org depends on scheduled processing. But mastering cron expressions isn’t hard once you understand the structure.
When you treat cron as a logical rule instead of a magic string, scheduling becomes predictable.
That’s the difference between copying examples and actually controlling automation.
Support
Got questions about implementing scheduled jobs in your org? Raise a ticket, and our team can point you in the right direction.
For more Salesforce development tips and tricks, check out our other guides on Apex Programming, Apex Test Class in Salesforce, and Batch Apex.

Be the first to comment.