The easiest way is to use UserInfo.getName() method.
If (UserInfo.getName() != 'Some User Name') {
// Do processing here
}
I would recommend to have this implemented by profile instead
If (UserInfo.getProfileId() != 'Certain Profile ID') {
// Do processing here
}
But if you want to have support for multiple users, you should use a map or a set to make this more maintainable.
Set<ID> bannedIds = new Set<ID>();
bannedIds.add('ID1');
bannedIds.add('ID2'); // add more ids to ban
if ( ! bannedIds.contains(UserProfile.getProfileId()) ) {
// do processing here
}
The easiest way is to use UserInfo.getName() method.
If (UserInfo.getName() != 'Some User Name') {
// Do processing here
}
I would recommend to have this implemented by profile instead
If (UserInfo.getProfileId() != 'Certain Profile ID') {
// Do processing here
}
But if you want to have support for multiple users, you should use a map or a set to make this more maintainable.
Set<ID> bannedIds = new Set<ID>();
bannedIds.add('ID1');
bannedIds.add('ID2'); // add more ids to ban
if ( ! bannedIds.contains(UserProfile.getProfileId()) ) {
// do processing here
}
Step 1 : - create a new custom filed on the user object. ( Bypass_Trigger__c) Data type is checkbox ..
If this checkbox is checked to any user the trigger wnt execute to the user ...
// Query the salesforce current logged in user
User u=[Select Bypass_Trigger__c
from User
where id=:UserInfo.getUserId()] ;
// Check if the current user is allowed to bypass the trigger
if(!u.Bypass_Trigger__c){
// YOUR Loggic
}
Im trying to do something similar in my org. Bypass a specific user for the account trigger, getting the following error.
Variable does not exist: Bypass__c
This is my code: trigger Deleteaccount on Account (before insert) { // Query the salesforce current logged in user User u=[Select Bypass__c from User where id=:UserInfo.getUserId()] ; // Check if the current user is allowed to bypass the trigger if(!u.Bypass__c){
I would recommend to have this implemented by profile instead
But if you want to have support for multiple users, you should use a map or a set to make this more maintainable.
All Answers
I would recommend to have this implemented by profile instead
But if you want to have support for multiple users, you should use a map or a set to make this more maintainable.
Step 1 : - create a new custom filed on the user object. ( Bypass_Trigger__c) Data type is checkbox ..
If this checkbox is checked to any user the trigger wnt execute to the user ...
Im trying to do something similar in my org. Bypass a specific user for the account trigger, getting the following error.
Variable does not exist: Bypass__c
This is my code:
trigger Deleteaccount on Account (before insert) {
// Query the salesforce current logged in user
User u=[Select Bypass__c
from User
where id=:UserInfo.getUserId()] ;
// Check if the current user is allowed to bypass the trigger
if(!u.Bypass__c){
for(Account acc : trigger.old){
if(Bypass__c == 'true'){
acc.adderror('Account Cannot be deleted');
}
}
}
}
Thank yoU!