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

Test Method for a Email Trigger
Hi,
Need help on the below trigger for the lines marked in red. I am able to cover 52% of code, but I am facing difficulty for the below lines marked in red.
trigger SurveyGuest on SurveyTaker__c (before insert,before update)
{
for(SurveyTaker__c st:trigger.new)
{
st.Guest_Profile__c=st.hg__c;
try
{ Visit_Details__c vs =[Select Overal_Points__c,Guest_Name__c from Visit_Details__c where id=:st.Transaction_Detail__c];
Survey__c sr =[Select id ,Maximum_Points__c,Points_Required_Minimum__c,Email_Template_Id__c,Email_Address__c, Points_for_Loyalty_programme__c from Survey__c where id=:st.Survey__c];
if(vs.Overal_Points__c==null)
vs.Overal_Points__c=0;
vs.Overal_Points__c = vs.Overal_Points__c+ sr.Points_for_Loyalty_programme__c ;
st.Guest_Profile__c=vs.Guest_Name__c;
if(((st.Points_Earned__c/sr.Maximum_Points__c)*100)<sr.Points_Required_Minimum__c)
{
EmailTemplate e = [select Id,Name,Subject,body ,htmlvalue from EmailTemplate where Id=:sr.Email_Template_Id__c];
List <String> toAddresses =new List <String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
toAddresses.add(sr.Email_Address__c);
mail.setToAddresses(toAddresses);
if((e.htmlvalue!=null)&&(e.htmlvalue!=''))
mail.setHtmlBody(e.htmlvalue);
else
if((e.body !=null)&&(e.body !=''))
mail.setHtmlBody(e.body );
mail.setSubject(e.Subject);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
update vs;
}
catch(exception e)
{
}
}
}
Kindly help ASAP.
if(vs.Overal_Points__c==null)
vs.Overal_Points__c=0;
you will need to create a test class that tests this as true AND false. This can ba done by setting inserting 2 SurveyTaker__c or updating the one you insert.
I dont know what your test class is doing but I imagen that this conditional statement is not true either.
if(((st.Points_Earned__c/sr.Maximum_Points__c)*100)<sr.Points_Required_Minimum__c)