You need to sign in to do that
Don't have an account?
Test class for batch apex
Hi,
I have created batch class, but i am facing problem during code coverage.
can any one tell me how to write test class?
here is my class:
global class expireNotify implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext bc)
{
Date d = Date.today();
String soql = 'SELECT Expiry_Date__c, Name, Email_Address__c FROM Member__c WHERE Expiry_Date__c =: d';
return Database.getQueryLocator(soql);
}
global void execute(Database.BatchableContext bc, List<Member__c> recs)
{
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
for(Member__c m : recs)
{
List<String> toAddresses = new List<String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
toAddresses.add(m.Email_Address__c);
mail.setToAddresses(toAddresses);
mail.setSubject('Welcome to Sweet 16 Siebel Batch');
String messageBody = '<html><body>Hi ' + m.Name + ',<br>Your account Expires today. <br>Kindly contact your administrator.<br><br><b>Regards,</b><br>Magulan D</body></html>';
mail.setHtmlBody(messageBody);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc)
{
}
}
here is your test class for batch apex, giving 100% coverage
important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thanks,
Hitesh Patel