1. Create a Custom Field on the User object to store the user deactivate date time.
2. Use the following sample trigger on the User object.
Sample Code:
trigger UserTrigger on User (
before update
) {
Map < Id, User> UserMap = trigger.oldMap;
for (
User objUser : trigger.new
) {
if (
trigger.oldMap.get(
objUser.Id
).IsActive &&
!objUser.IsActive
) {
objUser.Deactivation_Date_Time__c = System.now();
} else if (
!trigger.oldMap.get(
objUser.Id
).IsActive &&
objUser.IsActive
) {
objUser.Deactivation_Date_Time__c = null;
}
}
}