You need to sign in to do that
Don't have an account?

Before vs After Update Trigger...your thoughts?
Hello all,
I have a Before Update trigger that is working mostly correct. I have added a custom field to User called Send_Deactivation_Alert__c (SDA).
I want the Admin to check the SDA box when a user has not signed on in a long time. I want my trigger to load 2 other fields when the SDA box is checked.
My problem is as soon as I open the User record the SDA gets checked somehow...is this becuse I am using Before Update?
trigger Load_Custom_User_Fields_Trigger on User (before update) {
for(User u:trigger.new){
if (u.Send_Deactivation_Alert__c=TRUE){
u.Last_Login_for_PB_Flows__c = u.LastLoginDate;
u.Managers_Email_for_PB_Flows__c = u.Managers_Email_del__c;
}
}
}
I think you just used wrong operator in the if condition :D . if (u.Send_Deactivation_Alert__c=TRUE){ , here instead of checking for true you are assigning a true value to Send_Deactivation_Alert__c.
Please use this instead : if(u.Send_Deactivation_Alert__c) or if(u.Send_Deactivation_Alert__c == TRUE)
Both are same.
Also this has nothing to do with the before of after trigger, this is just a typo.
Please like and mark as answer if this helps.
All Answers
*** Correction *** When I click on SAVE...u.Send_Deactivation_Alert__c gets loaded to TRUE and then u.Last_Login_for_PB_Flows__c and u.Managers_Email_for_PB_Flows__c get updated.
I don't know how or what is setting u.Send_Deactivation_Alert__c to TRUE?
I think you just used wrong operator in the if condition :D . if (u.Send_Deactivation_Alert__c=TRUE){ , here instead of checking for true you are assigning a true value to Send_Deactivation_Alert__c.
Please use this instead : if(u.Send_Deactivation_Alert__c) or if(u.Send_Deactivation_Alert__c == TRUE)
Both are same.
Also this has nothing to do with the before of after trigger, this is just a typo.
Please like and mark as answer if this helps.
Thank you so much...I just couldn't see the typo!
You are the best!!!