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
AMR27AMR27 

Need Tesclass for simple scoring trigger

Hey All,

 

I have written a trigger to fill a score field on a QA object that we use to vet Cases in the system for appropriate behavior.

 

I have atteched  both the trigger and the test class below; as of now it is not even hitting the trigger at all, so I assume I am missing something simple that will get the test class to call the trigger.

 

Please let me know what I am missing; I am going crazy with test classes for triggers lately and it must be something I am missing.

 

Thanks a lot!

 

Alex Roth

 

Trigger -

 

trigger Score on QA_Instance__c (before insert, before update) {

Decimal opening = 0;
decimal written = 0;
decimal Verbal = 0;
decimal listening = 0;
decimal empathy = 0;
decimal prof = 0;
decimal offer = 0;
decimal issue = 0;
decimal expect = 0;
decimal resource = 0;
decimal escalate = 0;
decimal create = 0;
decimal tool = 0;
decimal quality = 0;
decimal policy = 0;


For(QA_Instance__c qa: Trigger.new){

    If(qa.Case_Origin__c == 'Phone'){
    
        If(QA.Opening__c == 'Yes'){
        
            opening = 4;
            
            }
            
        If(QA.Listening_Skills__c == 'Yes'){
    
            listening = 7;
            
            }    
          
        If(QA.Empathy__c == 'Yes'){
    
            empathy = 7;
            
            }    
        
        If(QA.Communication_Skills_Verbal__c == 'Yes'){
    
            verbal = 8;
            
            }       
            
        If(QA.Communication_Skills_Written__c == 'Yes'){
        
            written = 7;
            
            }
        
        If(QA.Professional_Behavior__c == 'Yes'){
        
            prof = 8;
            
            }
        
        If(QA.Offer_Assistance__c == 'Yes'){
        
            offer = 4;
            
            }    
         
         If(QA.Issue_ID_and_Solution_Provided__c == 'Yes'){
        
            issue = 7;
            
            }  
           
         If(QA.Set_Expectations__c == 'Yes'){
        
            expect = 7;
            
            }
         
         If(QA.Resourcefulness__c == 'Yes'){
        
            resource = 7;
            
            }
         
         If(QA.Escalate_Transfer__c == 'Yes'){
        
            escalate = 4;
            
            }
         
         If(QA.Create_Case__c == 'Yes'){
        
            create = 8;
            
            }
         
         If(QA.Tool_Documentation__c == 'Yes'){
        
            tool = 8;
            
            }  
           
         If(QA.Quality_Documentation__c == 'Yes'){
        
            quality = 8;
            
            }   
           
         If(QA.Adherence_to_Policy__c == 'Yes'){
        
            policy = 6;
            
            }    
           
             If(QA.Professional_Behavior__c == 'No'){
           
               qa.Score__c = null;
           
               }
             Else{
         
               qa.Score__c = opening+written+verbal+listening+empathy+prof+offer+issue+expect+resource+escalate+create+tool+quality+policy;
           
               }  
       
           }
       
     If(qa.Case_Origin__c == 'Email'||qa.Case_Origin__c == 'Web'){
    
           
        If(QA.Listening_Skills__c == 'Yes'){
    
            listening = 9;
            
            }    
          
        If(QA.Empathy__c == 'Yes'){
    
            empathy = 9;
            
            }    
              
            
        If(QA.Communication_Skills_Written__c == 'Yes'){
        
            written = 10;
            
            }
        
        If(QA.Professional_Behavior__c == 'Yes'){
        
            prof = 10;
            
            }    
         
         If(QA.Issue_ID_and_Solution_Provided__c == 'Yes'){
        
            issue = 10;
            
            }  
           
         If(QA.Set_Expectations__c == 'Yes'){
        
            expect = 9;
            
            }
         
         If(QA.Resourcefulness__c == 'Yes'){
        
            resource = 9;
            
            }
         
         If(QA.Escalate_Transfer__c == 'Yes'){
        
            escalate = 6;
            
            }
         
         If(QA.Tool_Documentation__c == 'Yes'){
        
            tool = 10;
            
            }  
           
         If(QA.Quality_Documentation__c == 'Yes'){
        
            quality = 10;
            
            }   
            
          If(QA.Adherence_to_Policy__c == 'Yes'){
        
            policy = 8;
            
            }      
           
           
             If(QA.Professional_Behavior__c == 'No'){
           
               qa.Score__c = null;
           
               }
             Else{
         
               qa.Score__c = Math.roundtolong(written+listening+empathy+prof+issue+expect+resource+escalate+tool+quality+policy);
           
               }
       
            }
        
        
    }

}

 

TestClass - 

 

@isTest(seealldata=true)
private class TestScore {

    static testMethod void TestScore() {
    
    
        Test.startTest();
        
        RecordType RT = [select ID from RecordType where sObjectType = 'Case' AND Name = 'CSRCase'];

        Case newCase = new Case(RecordTypeId = RT.ID,
        Subject = 'Instant iPad Setup',
        Status = 'New',
        Deal_Type__c = 'Instant',
        Reason_for_Contact__c = 'iPad Set-Up - Outbound', 
        Resolution_Type__c = 'iPad Set-Up Complete', 
        Origin = 'Phone', 
        Case_Source__c = 'Instant Support');
      
        insert newCase;
        
        QA_Instance__c qa = new QA_Instance__c(
        Case_Origin__c = 'Phone',
        Professional_Behavior__c = 'Yes',
        Case__c = newCase.id);
        
        insert qa;
        
        qa.Score__c = 9;
        
        update qa;
        
        Test.stopTest();
        
        }
        
}

 

Starz26Starz26

Is your trigger active?

The simple act of inserting the record should at leat cover the first for loop...

 

What does your debug logs show?

Rajesh SriramuluRajesh Sriramulu

Hi

 

Try to insert the remaining fields according to if conditon so that every if condition will satisfies and code coverage will cover.

fileds like  Listening_Skills__c,Empathy__c,.... for QA_Instance__c object.