What is Scheduled Apex?
Scheduled apex or schedulable apex is all about running a piece of apex code at a specific time over a set period of time. Schedule apex is a Salesforce class that runs at regular intervals. To schedule an apex class, we must implement the Schedulable interface. If you want to run a piece of code on the first of every month or on a daily basis, you can use it to make your life easier when you have to redeploy/change this code. Apex scheduler runs in system mode, which means that whether the user has permission to execute the class or not, the class can be executed.
Every 10 minutes, a new scheduled apex job is added, and it's a great time to start a career as a Salesforce Developer. You can also access scheduled batch apex from the developer console with the proper code and approach.
Values of Expressions in Salesforce Apex
|
Name |
Values |
Special Characters |
|
Seconds |
0–59 |
None |
|
Minutes |
0–59 |
None |
|
Hours |
0–23 |
None |
|
Day_of_month |
1–31 |
, - * ? / L W |
|
Month |
1–12 or the following: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec |
, - * / |
|
Day_of_week |
1–7 or the following: Sun, Mon, Tue, Wed, Thu, Fri, Sat |
, - * ? / L # |
|
optional year |
null or 1970–2099 |
, - * / |
How to use expressions with 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. |
|
? |
No value |
|
* |
All Value |
|
L |
Last |
Scheduled apex in Salesforce Example
This scheduled apex in Salesforce is a bit complex and you need to put maximum dedication into understanding the concept of Scheduled apex in Salesforce.
Job Schedule
You may also directly query CronJobDetail to get the job's name and kind. Run the following query to get the total number of Apex scheduled jobs (excluding other scheduled job types). The CronJobDetail SOAP API object supports many job kinds.
Conclusion
This blog explains in detail what scheduled apex is and how to use scheduled apex in Salesforce to schedule several jobs at the same time.
A class in Salesforce called Schedule Apex runs at regular intervals. Implementing the interface Schedulable is necessary in order to schedule an apex class. Write an Apex class that implements the Schedulable interface if you wish to schedule it to execute at regular intervals.
Similarly, if needed for your project, you can learn about Salesforce objects, SOSL, and salesforce automation tools, as well as Salesforce methods. You can boost your career and display your Salesforce-verified credentials and resume-worthy abilities by taking an online salesforce training course. Best wishes!