Is there anyway I can update a contact email when the user's email is updated? I though this can be done via User trigger easily, but the problem is whenever the email gets updated from the User page, the user has to confirm first the updated email before the user email gets updated.
When the user clicks the confirmation link on the email, the trigger didn't fire(checked via debug logs). Thus, not updating the associated contact with it.
And I know that there is a workaround here wherein the user won't have to confirm the email if the "generate new password" is ticked, and I don't want to reset the user's password each time they have updated their email, so this is not an option.
Is there anyway around this?
Sample Code:
trigger UserTrigger on User (after update) {
if(Trigger.isUpdate && Trigger.isAfter) {
//ChatterUtility.AddToGroups(Set userIds)
Map<String, User> setUnamesCon = new Map<String, User>();
for(User u : Trigger.new) {
if (u.Email != Trigger.oldMap.get(u.Id).Email) {
setUnamesCon.put(u.contactId, u);
}
}
if(setUnamesAcc.size() > 0 && setUnamesAcc != null) {
List<Contact> lConForUpdates = new List<Contact>();
for(Contact con : [SELECT Id, Email FROM Contact WHERE id in: setUnamesCon.keySet()]) {
con.Email = setUnamesCon.get(con.Id).Email;
lConForUpdates.add(con);
}
update lConForUpdates;
}
}
}
Cheers