Back to Top

Complete Guide on Cron Expressions in Salesforce With Examples

Updated 12 February 2026

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.

Searching for an experienced
Salesforce Company ?
Find out More

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:

NameValue
Seconds0–59
Minutes0-59
Hours0-23
Day_of_month1-31
Month1-12
Day_of_week1-7
optional_yearnull 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

ExpressionDescription
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-FRIat 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#3at 5:15 PM on the third Friday of every month
0 0 18 ? * 6Lruns 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 * * ? 2016runs 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:

  1. An Apex class that implements the Schedulable interface.
  2. A cron expression that defines the schedule.
  3. 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.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home