You need to sign in to do that
Don't have an account?
Suraj 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();
}
}
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();
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.