+ Start a Discussion
Jennifer24wJennifer24w 

Trigger not functioning as expected

I'm new to writing Triggers this is my first one wirtten without help.  I'm not sure where I'm going wrong here but this is what I need it to do.  If the stage field is updated to Forfeit or Withdraw after action I need it to reomve all data in the fields in the trigger.  I got this up and running, but one issue.  It's basically making the fields null even when the stage isn't one of those two values.  I'm not sure where I'm going wrong with this.  Any help would be appreciated.

trigger RemoveUDF on Contact (before update) {
    for (Contact cont : Trigger.New)
    {
      If (cont.TargetX_SRMb__Student_Type__c == 'First-Time Freshman'&& (cont.TargetX_SRMb__Status__c == 'Forfeit'|| cont.TargetX_SRMb__Status__c == 'Withdraw-Stu WD After Act'))    
      {
            cont.Moravian_CA_UDEF_3A_3__c = Null;
            cont.Moravian_CA_UDEF_1A_4__c = Null;
            cont.Moravian_CA_UDEF_10A_1__c = Null;
            cont.Moravian_CA_UDEF_1A_10__c = Null;
            cont.Moravian_CA_UDEF_1A_1__c = Null;
            cont.Moravian_CA_UDEF_1A_2__c = Null;
            cont.Moravian_CA_UDEF_1A_3__c = Null;
            cont.Moravian_CA_UDEF_1A_5__c = Null;
            cont.Moravian_CA_UDEF_1A_6__c = Null;
            Cont.Moravian_CA_UDEF_1A_7__c = Null;
            Cont.Moravian_CA_UDEF_1A_8__c = Null;
            Cont.Moravian_CA_UDEF_1A_9__c = Null;
            Cont.Moravian_CA_UDEF_2A_1__c = Null;
            Cont.Moravian_CA_UDEF_2A_2__c = Null;
            Cont.Moravian_CA_UDEF_2A_3__c = Null;
            Cont.Moravian_CA_UDEF_3A_2__c = Null;
            Cont.Moravian_CA_UDEF_3A_3__c = Null;
            Cont.Moravian_CA_UDEF_3A_4__c = Null;
            Cont.Moravian_CA_UDEF_5A_1__c = Null;
            Cont.Moravian_CA_UDEF_5A_2__c = Null;
            Cont.Moravian_CA_UDEF_5A_3__c = Null;
            Cont.Moravian_CA_UDEF_5A_4__c = Null;
        }     
    }
}
Best Answer chosen by Jennifer24w
brahmaji tammanabrahmaji tammana
Can you try if condition as below.
If ( (cont.TargetX_SRMb__Student_Type__c == 'First-Time Freshman') && 
	( (cont.TargetX_SRMb__Status__c == 'Forfeit') || (cont.TargetX_SRMb__Status__c == 'Withdraw-Stu WD After Act'))
)

 

All Answers

brahmaji tammanabrahmaji tammana
Can you try if condition as below.
If ( (cont.TargetX_SRMb__Student_Type__c == 'First-Time Freshman') && 
	( (cont.TargetX_SRMb__Status__c == 'Forfeit') || (cont.TargetX_SRMb__Status__c == 'Withdraw-Stu WD After Act'))
)

 
This was selected as the best answer
Jennifer24wJennifer24w
That did it!  THANK YOU!!!!!!!!