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
AneeshaAneesha 

user email update

I am trying to update a few records with email id whenever a user updates his email in the user record. I wrote the trigger on User object however the trigger is not firing since an email is first sent over on email update which then requires confirmation from user. 

Any ideas on what can be done?
Best Answer chosen by Aneesha
AneeshaAneesha
Posting the solution I came up with.

Instead of writing the trigger on User object, I moved my trigger to the custom object in which the email needs to be updated. Works like a charm!

All Answers

Sonam_SFDCSonam_SFDC
I suppose you will have to disable the change email verification process to get this working on the User object record: read more  on how this can be made possible:
https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-disable-email-address-change-verification-for-my-org-1327108328107&language=en_US
AneeshaAneesha
That doesn't look like a feasible solution for me as only a few users from my instance will be actually needing the functionality mentioned above. I reckon the email verification disabling will affect the whole instance which is not desirable.
OnpursuitOnpursuit
Hi,

Maybe you can create a new field for email and if you add the email there too. Then it will trigger the operation. 
I dont think there will be a direct solution but this workaround can work as you have very less users who will use it.

Mark it as solved if it resolves the issue.

Thanks
Sonam_SFDCSonam_SFDC
Yes Aneesha, probably the above suggested workaround might work as you can then copy this email to the respective records.

However, there would be one challenge to update this field at the same time to change the email address/recieve confirmation from user to change the email address.
AneeshaAneesha
Hi Onpursuit,

Thanks for your suggestion. But I do not think this is a viable solution because there is a slightest chance that the email change is not confirmed by the end user. In which case all my records will have the new email address however the actual user record will have the old email address.

I am specifically looking for the event on which I can make my trigger fire. I am trying to understand what happens when the end user  confirms the email address change via mail? The user record gets updated however the after update trigger is not firing. Why is it so? Very confusing
OnpursuitOnpursuit
Hi,

Trigger do not fire when email confirmation link is clicked. Here is a Idea and you can vote on it (I have voted for you) - https://success.salesforce.com/ideaView?id=08730000000kyTtAAI

For workaround, you need to store the new email somewhere and write a schedule job. Which will check the new email and old email. When user clicks on email confirmation and after that scheduled job will run and make the required changes. Maybe you can add the email on event record and run some scheduled jobs. There is no direct solution.

Thanks,
Rahul 
AneeshaAneesha
Posting the solution I came up with.

Instead of writing the trigger on User object, I moved my trigger to the custom object in which the email needs to be updated. Works like a charm!
This was selected as the best answer