Problem – It is usually the requirement that we need some automated process that can automatically keep running at one particular time every day or after few days gap into your SalesForce org.
Solution – The possible solution is that, we can use Apex Schedulers. What is Scheduled Apex? Currently in the universe of SalesForce, if you want to align your set of codes and you want them to run a set time every day or on a particular time set by you, then your answer is Scheduled Apex. Scheduled Apex is like a job that gets executed from your org whenever it is scheduled for. For scheduling any apex code, all we need is to implement a Schedulable interface. This interface, when implemented contains only one ‘execute’ method which is mandatory to use. Basic Structure of Scheduled Apex After implementing your code in the Scheduled Apex, now the question is how we can schedule this Apex code. Well I will be sharing two ways to do it. Out of two ways one of the ways is a standard way and the other is a custom way to schedule an apex. Standard method of Scheduling an Apex Follow these steps to schedule an apex: –
- Click on SETUP
- In Quick Find/ Search box type ‘Apex Classes’ and click on the same
- Then click on ‘Schedule Apex Button’
- After clicking on the Schedule Apex button, you will see a page where you have to enter your scheduled job name, select Apex class to be scheduled, then select on what days you want to run your job – weekly/monthly, then enter the duration for how long your job will keep executing and what is preferred start time of your job.
- After entering required details, click on save
- Once saved, you can view your scheduled job. Click on setup, in search box, type ‘Scheduled Jobs’. Click on the same. You can view your scheduled job, when in was created, when it was executed last and when it will execute next.