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
hari0853701703454959hari0853701703454959 

How to write test class for below coding

Hi,
how to write test class for below coding.Plz help asap

global class Batch_to_SentEmailNotify implements Database.Batchable<sObject> 
 {
   global Database.QueryLocator start(Database.BatchableContext BC) 
    {
       string s='Blocked';
        String query = 'Select Resort_Master__r.Name,Executive_Name__r.Email__c,Name_of_the_Guest__c,Company_Name__c,Block_Release_Date__c,Check_In__c,Check_Out__c,Total_Number_of_Rooms_Booked__c,Booking_Status__c,Source__c,Market_Segment__c,Executive_Name__r.Name FROM Non_Member_Booking_Request__c where Booking_Status__c=: s';
        return Database.getQueryLocator(query);
    }
   
    global void execute(Database.BatchableContext BC, List<Non_Member_Booking_Request__c> scope) 
    {
         for(Non_Member_Booking_Request__c c : scope)
         {
           system.debug('++++++++++++++system.today ++++++++++++++'+system.today());
            string email = c.Executive_Name__r.Email__c;
            if(email !=null && (system.today() == c.Check_In__c))
            {
              Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
              mail.setUseSignature(false);
              mail.setToAddresses(new String[] { email});
              mail.setSubject('Booking Confirmation ');
              mail.setHtmlBody('Dear Team <br/>'+'Namaste !!!!<br/>'+'Please find the attached payment details of below room reservation.<br/>'+'Please check and confirm the CV with updated payment details.<br/>'
              );
              Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
              system.debug('@@@@@@@@@@@@@@@mail@@@@@@@@@@@@@@@'+mail);
            
           }
         }   
    }
    global void finish(Database.BatchableContext BC) 
    {
    }
}
Regards,
Hareesh
Dheeraj ChawlaDheeraj Chawla
Hello,
   
    Just Insert the object that you are using in your Batch Class  then after make the instance of your batch class like below

 Batch_to_SentEmailNotify b = new Batch_to_SentEmailNotify ();
        ID batchprocessid = Database.executeBatch(b);


then run your test class..Hope you will get the test coverage.

Cheers..!!!
hari0853701703454959hari0853701703454959
I need full code.I it possible in batch apex create html template Using object Non_Member_Booking_Request__c Regards, *Hareesh*
AzusfdcAzusfdc
Hi Hari,
Try for below link it will be helpful
http://www.infallibletechie.com/2013/09/test-class-for-batch-apex-in-salesforce.html

Regards,
Azusfdc
hari0853701703454959hari0853701703454959
Hi, How to write test class for as per above code .Plz help and very urgent. Regards, *Hareesh*