Schedular Class in Salesforce | Apex Developer Guide
Scheduler Class
To arrange a Pinnacle course to run at standard extends, to begin with, compose a Pinnacle lesson that actualizes the Salesforce-provided interface Schedulable. The scheduler runs as a system—all classes are executed, whether or not the client has the authorization to execute the class. To screen or halt the execution of a booked Pinnacle, Apex Summit Pinnacle work utilizing the Salesforce UI from Setup, enter Planned Occupations within the Fast Discover box, at that point select Planned Jobs.
The Schedulable interface contains one strategy that must be actualized, execute.
global void execute(SchedulableContext sc){}
The strategy must be worldwide or public. We need to utilize this strategy to instantiate the course you need to schedule. The following lesson executes the Schedulable Interface here.
global class scheduleExample implements Schedulable { global void execute(SchedulableContext SC) { mergeClass M = new mergeClass(); } }
Don't forget to check out: Testing HTTP Callouts using SFCraft MockServer: Part 1 | Salesforce Help Guide
Execute strategy will take the SchedulableContext object as a contention which will assist with following the booked activity once it's planned. The SchedulableContext getTriggerID strategy restores the ID of the CronTrigger object related to this booked activity as a string. You'll request CronTrigger to take after the headway of the booked job. To halt the execution of an occupation that was arranged, utilize the System.abortJob procedure with the ID returned by the getTriggerID method. Here is the illustration code.
Scheduling apex
You can plan the Salesforce pinnacle by utilizing System.Schedule technique or by utilizing Salesforce UI. The primary contrast is Salesforce UI won't bolster the Schedule work in Seconds and minutes which should be possible with System.Schedule.The System.Schedule technique utilizes the client's timezone based on all timetables, yet runs in framework mode—all classes are executed, regardless of whether the client has the authorization to execute the class. The System.Schedule strategy takes three contentions: a name for the activity, an articulation used to speak to the time and date the activity is booked to run, and the name of the class. This articulation has the accompanying language structure.
Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year
- A simpler method to plan a bunch of work is to call the System.scheduleBatch technique without executing the Schedulable interface.
- Utilize the SchedulableContext article to monitor the planned activity once it's booked. The SchedulableContext getTriggerID strategy restores the ID of the CronTrigger object related to this booked activity as a string. You can question CronTrigger to follow the advancement of the planned activity.
- To stop the execution of a vocation that was booked, utilize the System.abortJob strategy with the ID returned by the getTriggerID technique.
You'll Plan Your Work utilizing Client Interface
- Go To Apex Classes.
- Click Schedule Apex
- Click Save.
Monitoring
After the Apex work has been booked you can follow the calendar subtleties from the CronTrigger ctt = [SELECT TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobID];
- The jobID variable holding the ID of the movement. The System.schedule technique reestablishes the movement ID. In case you're playing out this address interior the execute strategy for your schedulable lesson, you'll be able to get the ID of the show put of work by calling getTriggerId on the SchedulableContext dispute variable. Tolerating this variable title is sc, the modified demonstrate gets to be.
CronTrigger jobb = [SELECT Id, CronJobDetail.Id, CronJobDetail.Name, CronJobDetail.JobType FROM CronTrigger ORDER BY CreatedDate DESC LIMIT 1];
- You'll moreover arrive at the position's title and the activity's sort from the CronJobDetail record related to the CronTrigger record. To do as such, utilize the CronJobDetail relationship when playing out an address on CronTrigger. This show recoups the most recent CronTrigger record with the action title and sort from CronJobDetail.
Things to Remember
1. Salesforce plans the course for execution at the foreordained time. Genuine execution might be deferred dependent on administration accessibility.
2. You can just have 100 booked Apex occupations one after another
3. Utilize outrageous consideration in case you're wanting to plan a class from a trigger. You should have the option to ensure that the trigger won't include more planned classes than the cutoff.
4. On the off chance that there are at slightest one energetic booked occupations for a Summit course, you can't revive the lesson or any classes referenced by this course through the Salesforce UI. In any case, you can empower arrangements to refresh the class with dynamic planned employment by utilizing the Metadata API (for instance, when utilizing the Force.com IDE.
Check out another amazing blog by Marziya here: Salesforce Lightning Design System for Developers | The Ultimate Guide
5. Coordinated Web administration callouts are not upheld from booked Apex.
6. The most extreme number of planned Apex executions per a 24-hour time frame is 250,000 or the quantity of client licenses in your association increased by 200, whichever is more prominent. This cutoff is for your entire organization and is conferred to all nonconcurrent Pinnacle: Clump Pinnacle, Queueable Pinnacle, booked Summit, and future methodologies.
7. Summit employments planned to run amid a Salesforce benefit upkeep downtime will be planned to run after the benefit comes back up, when framework assets ended up accessible. On the off chance that a planned Summit work was running when downtime happened, the work is rolled back and planned once more after the benefit comes back up.
Thank you!
Reference: rajvakati
Responses