+ Start a Discussion
shasha777shasha777 

BATCH CLASS AND SCHEDULER CLASS?

Hi to all,

 

what is Batch class and scheduler class?

gautam_singhgautam_singh



Batch Class
Schedular Class

 

 

Click the above links to get more information about Batch and Schedular Class. In Simple terms we can define ... Batch Class is for doing manipulations over large number of records while Schdular class schedules the class for required time .


Batch Apex always requires 4 things ..

To Implement Database.Batachable<sObject>

start() , finish(),execute() methods

 

global class classname implements Database.Batachable<sObject>{

                global Database.querylocator start(Database.BatachableContext BC){

                return Databse.getQueryLocator(query);

                }

global void execute(Database.BatchableContext BC , List<sObject> scope) {

                }

                global void finish(Database.BatchableContext BC){

                }

 

 

Moreover, 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});

                        }

            }

Important :

Hit Kudo's if you find useful information from this post and if is the solution to your answer please mark it as a solution .