Find your content:

Search form

You are here

Determining user invoking action within Trigger


I recently had to implement some logic in a trigger to stop users from being able to add Attachments to a locked record of a particular type, and now I need to be able to create a "loophole" for a certain user (essentially, admin power to override the trigger). What I can't figure out is how to determine within a trigger (that could have multiple items in it) who the user is that invoked the action. I'm currently running before insert/update/delete, and think I could leverage the modifiedby of after insert/update for those, but I don't see a good way to know anything about delete. Any ideas?

Attribution to: Michael Welburn

Possible Suggestion/Solution #1

Another trick is to add a custom field on User (potentially a Checbox) - ByPassValidations__c or such. You can then check the User using UserInfo.getUserId() and query to see if the User has this checkbox set. This is slightly more scalable if you need to apply this for multiple users.

Attribution to: techtrekker

Possible Suggestion/Solution #2

You can get the current Users Id by using


From there you should be able to retrieve any extra info about the User that you need using queries.

Attribution to: Jon Hazan
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content