Batch Apex is a very powerful tool that allows us to work on large volumes of data in bite-sized chunks (batches) so that we don’t hit Salesforce’s governor limits. Often, we need to schedule our batch apex to run at a specified time, and at that time we need Scheduled Apex as well.
What if we could put all under one apex so we can have an easily started batch job that’s easy to schedule?
All we need to do is to implement Schedulable Class and then add its mandate method “execute(SchedulableContext SC)” which will contain code to execute the batch file. Refer to Screenshots 1 and 2.
Once done with it then to schedule the batch at desired time and day follow the steps below:
- Open Setup and Search Apex Classes.
- Inside Apex classes open Schedule Apex.
- Then Give desired job Name and select the apex class.
- Then select Schedule frequency as weekly or monthly and also its start date and end date.
- Set preferred start time and save the job.
This will create the scheduled job that will run our batch class at our scheduled time. Refer to screenshot 3.