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
jenny_j_chen1.3971006870153901E12jenny_j_chen1.3971006870153901E12 

How to catch user info change like email change or a user is frozen in a user trigger (after update)?

We are catching history of users in a custom object, called UserHistory.  I used Trigger on User and i can catch most info changes except user email change and if user is frozen (by the freeze button). 

The issue with email : Salesforce is not changing user email, it sent an email to the new and old email address. However, inside the user trigger, oldValue and newValue of email are the same, so it did not catch the change. 

The issue with frozen user : i don't see any field or flag on user, what can i do?
Thank you for your help.
kgilkgil
The frozen user information is stored in the UserLogin object, which you can not define a trigger for directly.

As a very basic example you can pull the IsFrozen value when the trigger is fired and do something with it, however I do not know of a way to get the trigger to fire every time it is changed due to it being in another object. 

trigger TestUserLoginFrozen on User (after update) {
    for (User u : Trigger.new){  
        UserLogin ul = new UserLogin();
        ul = [SELECT UserId, IsFrozen
                 FROM UserLogin
                 WHERE UserId = :u.Id];
        System.debug(ul.IsFrozen);
    }
}