function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rao venkyrao venky 

profiles trigger

Hello, sorry for the my language
 Can we bypass the trigger logic to particular profile? if yes how?
Himanshu ParasharHimanshu Parashar
Hi Rao,

You can write your logic something like this.
 
trigger ByPassTrigger on Account (before update) {

    //Get User profile details.
    User usr = [select Id,Profile.Name from User where Id = :userInfo.getUserId()];
    
    for(Account et : Trigger.new)
    {
        if(usr.Profile.Name.toLowerCase()=='Sales user')
        {
            //Write your logic here.
        }     
    
    }

}

Thanks,
Himanshu
Salesforce Certified Developer, Administrator, Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.Himanshu
surasura
you can user the below query to get logged users profile
 
Profile UserPROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId() LIMIT 1];

and you can use the UserProfile Varabile to skip any trigger validation 
eg:
 
if (UserProfile.Name != 'System Administrator')
{




}

 
Jayant JadhavJayant Jadhav
Hi Rao,

You can achive this by using UserInfo.getProfileId() method, This method return value of current user profile id. Try below code.
 
trigger profileExe on Demo(After insert)
{
         
        Id profileid=[Select Id,Name from Profile where Name ='System admin'].Id;
       if(userinfo.getProfileId()==profileid)
      {

          // bypass
      }
       else
     {
         // execute stmt
     }

}

Above trigger bypass for System admin profile.