• Ram Srivastav 7
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Salesforce developer
  • Wipro

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
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(){
    if(run){
     run=false;
     return true;
    }else{
        return run;
    }
    }
}

Apex Trigger code snippet: 

trigger sendEmail on Case (after insert,after update) {
   Public static Boolean InitialEmail =false;
   Public static Boolean FinalEmail =false;
 
  if(checkRecursive.runOnce()){
    
     for(Case c:trigger.new) {
    
      system.debug('outside'+c.Send_Email_to_Contact__c);
    
       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')) {
               system.debug('??????'+c.Send_Email_to_Contact__c);
           system.debug('Ram');
               sendEmailMessage(c.id,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')) {
            
                system.debug('****************'+c.Send_Email_to_Contact__c);
            
                sendFinalEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c);
        }
      
       }
}


Apex test class: code coverage just 52%

@isTest
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='freak.abhinav@gmail.com');
insert cs;

cs.Status='Completed';
update cs;
}
Hello,

I have defined apex trigger code which is working fine but the issue is with code coverage, its showing only 73% while deploying it into the production. Please help

Code snippet: 

trigger sendEmail on Case (after insert,after update) {
   Public static Boolean InitialEmail =false;
   Public static Boolean FinalEmail =false;
 
    //adding for check of trigger behaviour
     if(checkRecursive.runOnce())
    {
     for(Case c:trigger.new) {
      
        system.debug('outside'+c.Send_Email_to_Contact__c);
      
        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')) {
              
              system.debug('??????'+c.Send_Email_to_Contact__c);
             
              sendEmailMessage(c.id,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')) {
               
                system.debug('****************'+c.Send_Email_to_Contact__c);
               
                sendFinalEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c);
        }
    }
}
Hi,

I have defined Apex triggers on after insert which will fire the email on per case basis. Issue is same email is firing twice. Could any one help to get it solve..

trigger sendEmail on Case (after insert,after update) {
    Public static Boolean InitialEmail =false;
  
     for(Case c:trigger.new) {
       
        system.debug('outside'+c.Send_Email_to_Contact__c);
       
        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')) {
               
                system.debug('??????'+c.Send_Email_to_Contact__c);
              
                    sendEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
        }
       
}       
       
       
Hi,

I have defined Apex triggers on after insert which will fire the email on per case basis. Issue is same email is firing twice. Could any one help to get it solve..

trigger sendEmail on Case (after insert,after update) {
    Public static Boolean InitialEmail =false;
  
     for(Case c:trigger.new) {
       
        system.debug('outside'+c.Send_Email_to_Contact__c);
       
        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')) {
               
                system.debug('??????'+c.Send_Email_to_Contact__c);
              
                    sendEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
        }
       
}       
       
       
Hello,

I have defined apex trigger code which is working fine but the issue is with code coverage, its showing only 73% while deploying it into the production. Please help

Code snippet: 

trigger sendEmail on Case (after insert,after update) {
   Public static Boolean InitialEmail =false;
   Public static Boolean FinalEmail =false;
 
    //adding for check of trigger behaviour
     if(checkRecursive.runOnce())
    {
     for(Case c:trigger.new) {
      
        system.debug('outside'+c.Send_Email_to_Contact__c);
      
        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')) {
              
              system.debug('??????'+c.Send_Email_to_Contact__c);
             
              sendEmailMessage(c.id,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')) {
               
                system.debug('****************'+c.Send_Email_to_Contact__c);
               
                sendFinalEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c);
        }
    }
}
Hi,

I have defined Apex triggers on after insert which will fire the email on per case basis. Issue is same email is firing twice. Could any one help to get it solve..

trigger sendEmail on Case (after insert,after update) {
    Public static Boolean InitialEmail =false;
  
     for(Case c:trigger.new) {
       
        system.debug('outside'+c.Send_Email_to_Contact__c);
       
        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')) {
               
                system.debug('??????'+c.Send_Email_to_Contact__c);
              
                    sendEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
        }
       
}