+ Start a Discussion

Trigger Permissions? User based trigger?

I Have a trigger that needs to fire only for certain users.... Well to be honest it more accurately needs to NOT fire for 1 particular user.

Is there anyway this can be done? Can I check "$Current.User" or something like that in my trigger code?

I know I can have a trigger that will fire based on a users profile and permissions but, I still need the user to have "read / edit / create" priveleges for a certain object I just don't want them to have permission to fire the trigger that is on that object.

Anyhelp as always greatly appreciated. Thanks :)

Message Edited by patske on 08-03-2008 06:28 AM
I'm not sure I completely understand your request.  But let me take a shot at answering it.

The CRUD settings in the user's profile will limit their ability to directly access objects.  This should solve most situations. 

If you need more flexibility, you can use the UserInfo static methods to evaluate the running user.  If you want to inspect CRUD for the running user - you can also employ the describe classes/methods, eg:
Schema.DescribeSObjectResult d = Account.SObjectType.getDescribe();   // returns a describesobjectresult object - which you can leverage to evaluate CRUD for the running user. 

//Assuming the running user does not have Create permissions on account:
System.debug(d.isCreateable()); //would return false

How about looking at "Last Modified By"? If it's somebody you don't like, you could 'undo' the change or give an error message.

That will work for one person, or you could expand it to a group or Profile by seeing if that particular user is in that group/Profile.
ALL good guys I got this one sorted :)

Thanks for the help I ended up going with UserInfo.getUserId();

so thanks for that one tmatthiesen I completely forgot about the User Methods, Oh well I'm an idiot..

Thanks again guys :)