A cron expression is used to define scheduled jobs or tasks that run automatically at specified intervals. These expressions are a way to set up scheduled jobs in Salesforce that execute Apex code or other scheduled tasks on a regular basis.
A cron expression is a string consisting of 6 or 7 fields separated by spaces, each field representing a different time unit.
" Seconds Minutes Hours Day_of_Month Month Day_of_Week "
Parts of Cron Expression | Possible Values | Supported Special Characters |
---|---|---|
Seconds | 0 to 59 | none |
Minutes | 0 to 59 | none |
Hours | 0 to 23 | , - * / |
Day_of_month | 1 to 31 | , - * ? / L |
Month | 1 to 12 or JAN to DEC | , - * / |
Day_of_week | 1 to 7 or SUN to SAT | , - * ? / L # |
Special Character | What it does | Example |
---|---|---|
* | It indicates all valuesIt means 'Every' | 0 30 10 * * * means “10:30 AM every day.” |
? | It Indicates no specified valueIt means 'Any'it can only be used in Day_of_month and Day_of_week | 0 0 12 5 1 ? means “12:00 PM on the 5th day of January” (whatever day of the week that is). |
, | It indicates separates value.It means “and.” | 0 0 12 1 3,4,5 ? means "12.00 PM on 1st day of March,April & May" |
- | It indicates time range It means "From...To.." | 0 0 10-14 ? * SUN means "from 10 am to 2 pm every sunday" |
/ | It indicates Increments. The number before the slash specifies when the interval begins. The number after the slash is the interval. | 0 0 1/3 * * * means “starting from 1:00 AM every 3 hours every day.” |
# | It indicates the nth weekday of the month.it can only be used for Day_of_week The value before # sign is the weekday. The value after is the occurrence. | 0 0 12 ? * 5#2 means “12:00 PM on the second Thursday of every month.” |
L | It indicates the end of a range.It means as “last”.it can only be used in Day_of_month and Day_of_week | 0 0 12 L */1 ? means “12:00 PM on the last day of the month” |
Here are some common Cron expressions used in Salesforce for various scheduled job:
This tool helps you build Salesforce Cron expressions with an easy-to-use interface. It allows you to input values for each field and provides a human-readable description of the resulting schedule.