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
Alan DePewAlan DePew 

Test Class not working for After Update Trigger

Hello, 

I am having trouble getting my test class to work with my after update trigger. When I run my test it is showing 0% code coverage. Can anyone help me to understand why it is not working?

Here is the trigger code:
trigger FUS_UGGR_Application_Submitted on TargetX_SRMb__Application__c (After Update) {
	
    For (TargetX_SRMb__Application__c A : Trigger.New) {
    
    //Update Submitted Application Contact record to "Applicant"
    String ContactId = Trigger.newMap.get(A.ID).TargetX_SRMb__Contact__c;
    String New_Stage = Trigger.newMap.get(A.ID).TargetX_SRMb__Stage__c;
    String Old_Stage = Trigger.oldMap.get(A.ID).TargetX_SRMb__Stage__c;
    String App_Type = Trigger.newMap.get(A.ID).TargetX_SRMb__Application_Type__c;
        
    Contact C = [select id from Contact where id = :contactid];
    
 	IF(New_Stage <> Old_Stage && New_Stage == 'Submitted' && App_Type <> 'Undergraduate Non-Degree Post Secondary'){
    C.UGGR_Student_Stage__c = 'Applicant';
               	
    Update C;
            
        }        
    }
}

Here is my test class:
@isTest
public class FUS_Test_UGGR_App_Submit {

   //Perform Tests
    static testMethod void ValidateUGGRAppSubmit() 
    {

    Contact c = new Contact(
        FirstName = 'Test', 
        LastName = 'Test'
    );
    Insert c;
   
    TargetX_SRMb__Application__c a = new TargetX_SRMb__Application__c(
        TargetX_SRMb__Contact__c = c.Id, 
        TargetX_SRMb__Application_Type__c = 'Undergraduate',
        TargetX_SRMb__Stage__c = 'In Progress'
    );
    
    Insert a;
    
    Test.StartTest();
    	a.TargetX_SRMb__Stage__c = 'Submitted';
    	Update a;
    Test.stopTest();
    }
}

 
Raj VakatiRaj Vakati
Your code is having an issue .. You have to use below SOQL while querying the contact record. After running test class make sure it is passing.


    Contact C = [select id,UGGR_Student_Stage__c  from Contact where id = :contactid];
 
trigger FUS_UGGR_Application_Submitted on TargetX_SRMb__Application__c (After Update) {
	
    For (TargetX_SRMb__Application__c A : Trigger.New) {
    
    //Update Submitted Application Contact record to "Applicant"
    String ContactId = Trigger.newMap.get(A.ID).TargetX_SRMb__Contact__c;
    String New_Stage = Trigger.newMap.get(A.ID).TargetX_SRMb__Stage__c;
    String Old_Stage = Trigger.oldMap.get(A.ID).TargetX_SRMb__Stage__c;
    String App_Type = Trigger.newMap.get(A.ID).TargetX_SRMb__Application_Type__c;
        
    Contact C = [select id,UGGR_Student_Stage__c  from Contact where id = :contactid];
    
 	IF(New_Stage <> Old_Stage && New_Stage == 'Submitted' && App_Type <> 'Undergraduate Non-Degree Post Secondary'){
    C.UGGR_Student_Stage__c = 'Applicant';
               	
    Update C;
            
        }        
    }
}



 
Ryan GreeneRyan Greene
Alan, your Test looks good along with the Trigger. Are you getting an error running the Test code? Maybe there is an extra required field in the Contact or TargetX_SRMb__Application__c that you are missing?