function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MunmunMunmun 

Apex sheduler

Hi,

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

Pradeep_NavatarPradeep_Navatar

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)

                                {

                                                sendmail();

                                }

 

                                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');

                                                email.setToAddresses(toaddress);

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

                                }

                }

 

Hope this helps.

MunmunMunmun

Thanks  Its Seems to be working