You need to sign in to do that
Don't have an account?
Hannah Campbell
need help making a test class
public class EmailHandler {
public static void sendEmail2(){
// Create Email and Send
Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setCcAddresses(new String[] {'sample@sample.com'});
msg.setTemplateId('email'); //Use the custom HTML Template
msg.setTargetObjectId('003p000000Nklh9');
msg.setSenderDisplayName('Administrator');
msg.setSaveAsActivity(false); // so that it wont be saved as an activity
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { msg });
}
}
public static void sendEmail2(){
// Create Email and Send
Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setCcAddresses(new String[] {'sample@sample.com'});
msg.setTemplateId('email'); //Use the custom HTML Template
msg.setTargetObjectId('003p000000Nklh9');
msg.setSenderDisplayName('Administrator');
msg.setSaveAsActivity(false); // so that it wont be saved as an activity
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { msg });
}
}
Test class for the above class:
@isTest
public class Test_SimpleEmail {
@isTest static void sendEmail(){
Contact c= new Contact();
c.LastName='Test Name';
insert c;
Profile p = [select id from profile where name LIKE '%Admin%'];
User u = new User(Alias = 'standt', Email='test@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='testEx@testorg.com');
insert u;
system.runAs(u){
EmailTemplate e = new EmailTemplate (developerName = 'test',FolderId=UserInfo.getUserId() , TemplateType= 'Text', Name = 'test'); // plus any other fields that you want to set
insert e;
}
EmailHandler .sendEmail2();
}
}
Thanks,
Sowmya.
You need to use the code like below
Test Class
Please find below the sample Test Class.
Business Class:
Test Class:
I hope it helps you.
Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas