+ Start a Discussion

Apex sheduler


Please some one let me know for apex scheduler with sample codeapex


Apex Scheduler can be used to schedule a controller to execute at certain time in future. Apex scheduler can also be used to avoid some governor limit. For an example (DML limit) in Trigger or Controller : For this we have to make a Contoller and to schedule this controller go to  Administration Setup->Monitoring->Scheduled Jobs. From there we have to select the Controller and provide some time and date to execute in future.


                Find below a sample code of the Apex Scheduler Controller to send an email at a certain time in future-


                global class apexscheduledclass Implements Schedulable


                                global void execute(SchedulableContext sc)





                                public void sendmail()


                                                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

                                                string [] toaddress= New string[]{'vkumar.sri@gmail.com'};

                                                email.setSubject('Testing Apex Scheduler');

                                                email.setPlainTextBody('Check apex schedulrr');


                                                Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});




Hope this helps.


Thanks  Its Seems to be working