Print this page

Apex Trigger on User fires twice if changes are made from My Settings page

Knowledge Article Number 000214486
Description If a user makes changes in the "Personal Information" or "Language & Time Zone" pages and clicks Save, any "user trigger" (Apex code) that's defined for that org can potentially be called twice. This behavior is working as designed. Only one of the two trigger invocations actually reports a change to the actual user attribute being changed. The other invocation can safely be ignored. 

Resolution The workaround in the trigger is to ignore the user object values that do not change. For example:

for(User newuser :
User olduser = Trigger.oldMap.get(newuser.ID); 
if (newuser.FirstName != olduser.FirstName)
{ do something... } // Only take action when the value has changed

promote demote