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
Suraj DemgundeSuraj Demgunde 

test class not covering execute method?

class:
global class ICC_ReminderEmails implements Database.Batchable<sObject>{
    
    
     global list<ICCWorkbench__c> start(Database.BatchableContext BC){
        return [select id,name,Organization_ID__c,Vendor_Name__r.name,Vendor_Name__r.Email__c,Vendor_Name__r.Email1__c,Vendor_Name__r.Email2__c,Vendor_Name__r.Group_Email__c,MppsubmittDate__c,CreatedDate from ICCWorkbench__c where Supplier_Status__c ='Submitted To Supplier' AND MppsubmittDate__c=Last_n_days:1];
   }

     global void execute(Database.BatchableContext BC, List<ICCWorkbench__c> scope){
        system.debug('Scope -->' + scope);
        List < Messaging.SingleEmailMessage > emails = new List < Messaging.SingleEmailMessage > ();
           
        for(ICCWorkbench__c wcb : scope){
                
                               List<String> emailAddress  = wcb.Vendor_Name__r.Group_Email__c.split(';'); 
                               System.debug(emailAddress);
                               if(wcb.Vendor_Name__r.Email__c != null)
                                emailAddress.add(wcb.Vendor_Name__r.Email__c);
                               if(wcb.Vendor_Name__r.Email1__c != null)
                                emailAddress.add(wcb.Vendor_Name__r.Email1__c);
                               if(wcb.Vendor_Name__r.Email2__c != null)
                                emailAddress.add(wcb.Vendor_Name__r.Email2__c);
                               Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                               email.setToAddresses(emailAddress);
                               email.setSubject('Reminder For Pending Po Acknowledge '); 
                               email.setPlainTextBody('Dear User,' +' '+
                                                                'Your PO Number '+' '+wcb.Name +' ' + 'Pending For Acknowledge if Already Acknowledge then Ignore  this Mail otherwise Submit it immedietly.');
                                                      
                               emails.add(email);
                               system.debug('List Of Emails -->' + emails);
            
           
          }
       Messaging.sendEmail(emails);
      }
    
    global void finish(Database.BatchableContext BC){
   }
}

test class:

@isTest
Public class TestICC_ReminderEmails {  
public static testMethod void TestRemindermails(){   

//LisT<ICCWorkbench__c>  query = [select id,name,Vendor_Name__c ,Organization_ID__c,Vendor_Name__r.name,Vendor_Name__r.Email__c,Vendor_Name__r.Email1__c,Vendor_Name__r.Email2__c,Vendor_Name__r.Group_Email__c,MppsubmittDate__c,CreatedDate from ICCWorkbench__c where Supplier_Status__c ='Submitted To Supplier' AND MppsubmittDate__c=Last_n_days:1];
RecordType rtvnd = [select id,Name from RecordType where Name='Vender'];
ICCOrganization__c org = new ICCOrganization__c();
org.RecordTypeID = rtvnd.id;
org.Name ='test3';
//org.CurrencyIsoCode='';
org.Email__c = 'surajdem@gmail.com';     
org.Email1__c='surajdem@gmail.com';
org.Email2__c ='harshard.pansare@zamilindustrial.com'; 
org.Group_Email__c='surajdem@gmail.com;harshad.pansare@zamilindustrial.com';
insert org;
System.debug(org);

RecordType rtvnd1 = [select id,Name from RecordType where Name ='Manual FPO'];    
ICCWorkbench__c wcb = new ICCWorkbench__c();
wcb.RecordTypeID = rtvnd1.id;
wcb.Vendor_Name__c=org.id;
wcb.Name='hchchchchchc2';
wcb.MppsubmittDate__c= Date.newInstance(2014,1,21);
wcb.Organization_ID__c= '82';
wcb.Supplier_Status__c = 'Submitted To Supplier';
//wcb.Vendor_Name__r.Email__c  = org.Email__c;
//wcb.Vendor_Name__r.Email1__c= org.Email1__c;
//wcb.Vendor_Name__r.Email2__c = org.Email2__c;
//wcb.Vendor_Name__r.Group_Email__c=org.Group_Email__c;

//wcb.CurrencyIsoCode = 'EUR-Euro';

insert wcb;
System.debug(wcb);

test.startTest();  

//initiating an instance of the batch job   
ICC_ReminderEmails b = new ICC_ReminderEmails();
Database.executeBatch(b);

test.stopTest();  


}
}
Rameshwar gaurRameshwar gaur
You can not access Org record in Test Class. So SOQL queries Didn't get back any record. In Test Class You Need To Make Dummy Record And then Work On Them. May Be these Code help You To solve Your Problem.
@isTest
Public class TestICC_ReminderEmails {  
public static testMethod void TestRemindermails(){   

RecordType rtvnd = new RecordType(Name = 'Vender');
RecordType rtvnd1 = new RecordType(Name = 'Manual FPO');  
    Insert rtvnd;
    Insert rtvnd1;
ICCOrganization__c org = new ICCOrganization__c();
org.RecordTypeID = rtvnd.id;
org.Name ='test3';
//org.CurrencyIsoCode='';
org.Email__c = 'surajdem@gmail.com';     
org.Email1__c='surajdem@gmail.com';
org.Email2__c ='harshard.pansare@zamilindustrial.com'; 
org.Group_Email__c='surajdem@gmail.com;harshad.pansare@zamilindustrial.com';
insert org;
System.debug(org);
ICCWorkbench__c wcb = new ICCWorkbench__c();
wcb.RecordTypeID = rtvnd1.id;
wcb.Vendor_Name__c=org.id;
wcb.Name='hchchchchchc2';
wcb.MppsubmittDate__c= Date.newInstance(2014,1,21);
wcb.Organization_ID__c= '82';
wcb.Supplier_Status__c = 'Submitted To Supplier';
insert wcb;
System.debug(wcb);

test.startTest();  

//initiating an instance of the batch job   
ICC_ReminderEmails b = new ICC_ReminderEmails();
Database.executeBatch(b);
test.stopTest();  
    
}
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.