You need to sign in to do that
Don't have an account?
Mike @ BlackTab
Do Not Allow A Specific User To Run A Trigger
Inside of a trigger i'm trying to get information about the user updating the record. Is this possible?
Here is what my trigger looks like:
trigger ContactTriggers on Contact (after insert, after update) { if(Trigger.isAfter) { ContactTriggers.updateAccountLastCallAttemptFields(Trigger.new); } }
Here is what I need:
trigger ContactTriggers on Contact (after insert, after update) { if(Trigger.isAfter && [RunningUser != 'a user') { ContactTriggers.updateAccountLastCallAttemptFields(Trigger.new); } }
You can use the LastModifiedById field
trigger ContactTriggers on Contact (after insert, after update) {
User blocked = new User();
try{
blocked = [Select Id From User Where Name = 'a user'];
}catch(Exception e){
}
if(Trigger.isAfter && blocked.Id!=null && Trigger.new[0].LastModifiedById != blocked.Id) {
ContactTriggers.updateAccountLastCallAttemptFields(Trigger.new);
}
}
this code assumes that trigger.new has multiple records, they are modified by the same user. Also, if a list of users need to be used, the blocked variable could be made a set and comparison done using contains.