Activity › Forums › Salesforce® Discussions › Write a syntax and structure of scheduler class in Salesforce?
Tagged: Salesforce Development, Scheduler Class, Structure, Syntax
-
Write a syntax and structure of scheduler class in Salesforce?
Posted by Saurabh on May 11, 2017 at 3:11 PMWrite a syntax and structure of scheduler class?
Parul replied 7 years, 7 months ago 5 Members · 4 Replies -
4 Replies
-
Hi Saurabh,
global class ScheduleDemo implements Schedulable{
global void execute(SchedulableContext sc){
BatchClass b = new BatchClass();
database.executeBatch(b);
}
}Hope this will help you.
- [adinserter block='9']
-
Hi,
To invoke Apex classes to run at specific times, first implement the Schedulable interface for the class, then specify the schedule using either the Schedule Apex page in the Salesforce user interface, or the System.schedule method.
To schedule an Apex class to run at regular intervals, first write an Apex class that implements the Salesforce-provided interface Schedulable.
The scheduler runs as system—all classes are executed, whether or not the user has permission to execute the class.
To monitor or stop the execution of a scheduled Apex job using the Salesforce user interface, from Setup, enter Scheduled Jobs in the Quick Find box, then select Scheduled Jobs.
The Schedulable interface contains one method that must be implemented, execute.
global void execute(SchedulableContext sc){}
The implemented method must be declared as global or public.
The following example implements the Schedulable interface for a class called mergeNumbers:
global class scheduledMerge implements Schedulable {
global void execute(SchedulableContext SC) {
mergeNumbers M = new mergeNumbers();
}
}The following example uses the System.Schedule method to implement the above class.
scheduledMerge m = new scheduledMerge();
String sch = ’20 30 8 10 2 ?’;
String jobID = system.schedule(‘Merge Job’, sch, m);You can also use the Schedulable interface with batch Apex classes. The following example implements the Schedulableinterface for a batch Apex class called batchable:
global class scheduledBatchable implements Schedulable {
global void execute(SchedulableContext sc) {
batchable b = new batchable();
database.executebatch(b);
}
}Thanks
-
Hello,
Here is simple structure of Schedular Class-
global class BatchScheduleUpdate implements Schedulable { global void execute(SchedulableContext sc) { // Implement any logic to be scheduled // We now call the batch class to be scheduled BatchContactUpdate b = new BatchContactUpdate (); //Parameters of ExecuteBatch(context,BatchSize) database.executebatch(b,200); } }/pre> Thanks.-
This reply was modified 7 years, 7 months ago by
Avnish Yadav.
-
This reply was modified 7 years, 7 months ago by
-
Here some code snippet:
Apex scheduler is used to invoke Apex classes to run at specific times, first implement the Schedulable interface for the class, then specify the schedule using either the Schedule Apex page in the Salesforce user interface, or the System.schedule method.
The Schedulable interface contains one method that must be implemented, execute.
global void execute(SchedulableContext sc){}
The implemented method must be declared as global or public.The following example implements the Schedulable interface for a class called mergeNumbers:
global class scheduledMerge implements Schedulable{
global void execute(SchedulableContext SC) {
mergeNumbers M = new mergeNumbers();
}
}
The following example uses the System.Schedule method to implement the above class.
scheduledMerge m = new scheduledMerge();
String sch = ’20 30 8 10 2 ?’;
system.schedule(‘Merge Job’, sch, m);
You can also use the Schedulable interface with batch Apex classes. The following example implements the Schedulable interface for a batch Apex class called batchable:
global class scheduledBatchable implements Schedulable{
global void execute(SchedulableContext sc) {
batchable b = new batchable();
database.executebatch(b);
}
}Thanks
Log In to reply.