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
rajaram.adminrajaram.admin 

What is Schedule apex?explain one example

HI,

 

 

 

Thanks & Regards

Rajaram.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi

We use Apex Scheduler to schedule a controller to execute it at a given time in future. For this make an Apex Scheduler Controller and to schedule this controller go to...

 

Administration Setup->Monitoring->Scheduled Jobs from there we select that Controller class and then provide some time and date to execute it in future.

            Below is a sample code of the Apex Scheduler Controller to send an email :
            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-Subject');
                                    email.setPlainTextBody('Testing Apex Scheduler-Body');
                                    email.setToAddresses(toaddress);
                                    Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
                        }
            }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi

We use Apex Scheduler to schedule a controller to execute it at a given time in future. For this make an Apex Scheduler Controller and to schedule this controller go to...

 

Administration Setup->Monitoring->Scheduled Jobs from there we select that Controller class and then provide some time and date to execute it in future.

            Below is a sample code of the Apex Scheduler Controller to send an email :
            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-Subject');
                                    email.setPlainTextBody('Testing Apex Scheduler-Body');
                                    email.setToAddresses(toaddress);
                                    Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
                        }
            }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

This was selected as the best answer
sapthagiri_186sapthagiri_186

How can we call this sendmail() which is present in the mail controller.