+ Start a Discussion

Trigger on User email update

I need to detect the updates on the email field of the User object, and I'm having problems detecting this change.
I placed a trigger on the object on after Update , but at this point the logic displays the old email value on both the trigger.new and trigger.old maps.
Maybe it's related to the email salesforce sends to user, to confirm the email address change, so the email is actually updated when the confirmation address is accessed.
Did anyone run into the same problem? is this the only way of detecting the email field update on User?



No you can also set a workflow that have condition that whenver User's email changes it sends you an email, there is an ISCHANGE method


And about the trigger thing, take simple trigger.new and trigger.old in AFTER UPDATE event because whenver salesforce changes that Email your trigger is gonna run,

then fetch record from the database specially Email fields, 

 your definetly gonna get that difference in old email and new email.






Hi Abhi. I am working on this with the after update triggers. There is a problem because of the confirmation email sent when saving with the new value. If the user confirms the change from the email he recives, the user email will change but not the contact email. We know of a workaround by resetting the user password to avoid the confirmation email. But we would like to know if there is any other ways to avoid resetting the password. Thanks

Patrick TewsonPatrick Tewson
I'm experiencing a similar issue - I tried both with the original trigger on User and also attempted Abhi's suggested solution of setting up a workflow rule to fire a change when the email address changes. I can monitor the portal user in debug logs, and the trigger and the workflow rule both fire immediately when the updated portal user is saved - BEFORE the user email gets a chance to respond to the confirmation email and actually update the value of the email. As far as I've been able to tell, the 'real' change that comes about from responding to the confirmation email doesn't fire a trigger OR cause the workflow rule to fire. Everything else works - all the fields I'm mapping to contact do so succesfully, all my unit tests pass. I think it's the ordering of the verification email that's causing the issue, like some kind of behind-the-scenes process is responding to the portal user's confirmation that doesn't hit workflows and triggers like you would expect. 
Rahul Gawade 18Rahul Gawade 18
What patrick is saying exactly this is happening with me when i am trying update the email for a user. So anybody has any solution to this.
When user clicks on the link to confirm the email change trigger or workflow doesn't fire. Any solution?