function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ram Srivastav 7Ram Srivastav 7 

Code coverage issue

Hi, I have defined one trigger which used to intimate the user with acknowledgement mail. To prevent the same email twich i  do have defined one apex class. Issue is my test class is containing just 52% code coverage due to which i am not able to deploy my code change into the production. Please help

Apex class code snippet: Code coverage 100%

public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
     return true;
        return run;

Apex Trigger code snippet: 

trigger sendEmail on Case (after insert,after update) {
   Public static Boolean InitialEmail =false;
   Public static Boolean FinalEmail =false;
     for(Case {
       if ((trigger.isInsert || (trigger.oldMap.get(c.Id).Send_Email_to_Contact__c != c.Send_Email_to_Contact__c)) && (c.Send_Email_to_Contact__c && !c.Do_not_Send_Email__c  && c.Email_of_Complainant__c!=null && c.Status!='Completed')) {
               sendEmailMessage(,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
              if ((trigger.isInsert || (trigger.oldMap.get(c.Id).Status != c.Status)) && (c.Final_email_to_contact__c && !c.Do_not_Send_Email__c  && c.Email_of_Complainant__c!=null && c.Status=='Completed')) {

Apex test class: code coverage just 52%

public class TestClass_SendEmail{
static testmethod void SendEmails(){
Case cs = new Case(Status ='Outstanding',Complaint_Type__c ='Complaint',Query_Cause_Code__c='Disabled',Sub_Cause_Code__c ='Disabled',Send_Email_to_Contact__c=true,Final_email_to_contact__c=true,Email_of_Complainant__c='');
insert cs;

update cs;
Ravikant Saini 1Ravikant Saini 1
Hi Ram,
              I think you forget to fill this field.before insert.
c.Do_not_Send_Email__c = false;