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
Robert Wambold 10Robert Wambold 10 

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;
      }
    }
}

 

Best Answer chosen by Robert Wambold 10
NehaDabas16NehaDabas16
Hi Robert,

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

Robert Wambold 10Robert Wambold 10

*** 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?

NehaDabas16NehaDabas16
Hi Robert,

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.

 
This was selected as the best answer
Robert Wambold 10Robert Wambold 10

Thank you so much...I just couldn't see the typo!

You are the best!!!