+ Start a Discussion
KyoKyo 

Test Multi Condition

Trigger have multi Condition I can write Test Class has only 35% of you guide me !

 

 

trigger UpdateStatus on Case (Before update) {
    for(Case ca:Trigger.new){
         if(ca.New__c == False && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status != 'New'))
           {          
                if(ca.Status == 'Open 1st Level')
                        {ca.new__c = true;ca.O1L__c = False; ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False;  ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}            
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; }
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; ca.Reso__c = true; ca.Close__c = true;}
                
         } 

         else if(ca.New__c == True && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
         && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status != 'New'))
           {          
                if(ca.Status == 'Open 1st Level')
                        {ca.new__c = true;ca.O1L__c = False; ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False;  ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}      
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; }
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true; ca.Close__c = true;}
                
         } 
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False && ca.Reso__c == False && ca.Close__c == False && ((ca.Status != 'New') || (ca.Status != 'Open 1st Level')))
        {                                   
                if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}          
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;}
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true; ca.Close__c = true;}
                   
        }

 

@isTest
Private Class TestUpdateStatus{
    static testMethod void myTest1() {
            
            Case ca = new Case(Origin = 'Phone',Status = 'Open 1st Level',Function__c = 'CC',Type = 'Inquiry',new__c = true,O1L__c = False, O2L__c=False, IP1L__c=False, IP2L__c=False,  Reso__c=False, Cen__c=False);
            test.startTest(); 
            try{      
            insert ca;
            update ca;
            }catch(DMLException de){

        }  
            //Assert your results
            test.stopTest();
    }

   static testMethod void myTest2() {
            
            Case ca = new Case(Origin = 'Phone',Status = 'Open 2nd Level',Function__c = 'CC',Type = 'Inquiry',new__c = true,O1L__c = True);
            test.startTest();       
           try{      
            insert ca;
            update ca;
            }catch(DMLException de){

        }  
            //Assert your results
            test.stopTest();
    }

 

 

Thank you so much.

 

Prady01Prady01

Hello there.. I am also new to development on cloud.. But when i saw u code i understood that u are not able to traverse the other else if loops right???Using u test class.... The problem is u test class incomplete, what i mean is, U jave to add all the typed of data in u test class, U have only added till 

Status = 'Open 2nd Level
u have to add the data for 
ca.Status == 'In Progress 1st Level'
ca.Status == 'In Progress 2nd Level'
ca.Status == 'Resolved'
ca.Status == 'Closed'
ca.Status == 'Cancel'
hope it helps... sorry if it didnt!!!!