You need to sign in to do that
Don't have an account?

Apex Emails Testclass
Hi
Below is my code can anyone help with a testclass for it for max code coverage.
public class LeadEmail
{
public static void SendEmailTolead(list<lead> lstLead)
{
if(! lstLead.isEmpty())
{
list<messaging.SingleEmailMessage> lstEmails = new list<messaging.SingleEmailMessage>();
for(lead lr : lstLead)
{
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
string[] toEmailsIds = new string[]{lr.Email};
email.settoAddresses(toEmailsIds);
email.setTargetObjectId( UserInfo.getUserId() );
email.setSaveAsActivity( false );
email.setSenderDisplayName('lead Record Creation Alert');
email.setReplyTo('support@RFI.com');
string emailsubject = 'congralutions'+lr.Name+'you have been registerd';
email.setSubject(emailsubject);
string emailHTMLContent = 'Dear'+lr.name+',<br/> <br/>'+
'<br/><br/> here are your details... <br/><br/>'+
'<br/> Your Company....'+lr.Company+
'<br/> Your tile for the Role'+lr.Title+
'<br/> your Status for The record'+lr.Status+
'thanks & Regards';
email.setHtmlBody(emailHTMLContent);
lstEmails.add(email);
}
if(!lstEmails.isempty())
{
Messaging.sendEmail(lstEmails); }
}
}
}
Thanks in advance
Below is my code can anyone help with a testclass for it for max code coverage.
public class LeadEmail
{
public static void SendEmailTolead(list<lead> lstLead)
{
if(! lstLead.isEmpty())
{
list<messaging.SingleEmailMessage> lstEmails = new list<messaging.SingleEmailMessage>();
for(lead lr : lstLead)
{
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
string[] toEmailsIds = new string[]{lr.Email};
email.settoAddresses(toEmailsIds);
email.setTargetObjectId( UserInfo.getUserId() );
email.setSaveAsActivity( false );
email.setSenderDisplayName('lead Record Creation Alert');
email.setReplyTo('support@RFI.com');
string emailsubject = 'congralutions'+lr.Name+'you have been registerd';
email.setSubject(emailsubject);
string emailHTMLContent = 'Dear'+lr.name+',<br/> <br/>'+
'<br/><br/> here are your details... <br/><br/>'+
'<br/> Your Company....'+lr.Company+
'<br/> Your tile for the Role'+lr.Title+
'<br/> your Status for The record'+lr.Status+
'thanks & Regards';
email.setHtmlBody(emailHTMLContent);
lstEmails.add(email);
}
if(!lstEmails.isempty())
{
Messaging.sendEmail(lstEmails); }
}
}
}
Thanks in advance
Hi
Please find the Solution with 100% coverage.
Please let me know it is working or not?
Please mark it as the Best Answer so that other people would take reference from it.
Thank You
All Answers
Hi
Please find the Solution with 100% coverage.
Please let me know it is working or not?
Please mark it as the Best Answer so that other people would take reference from it.
Thank You
Try Below Code Please mark it as the Best Answer So it helps other in future
Thank You