+ Start a Discussion
john8407john8407 

Help with Trigger-UserInfo.getUserName

Trying to keep a trigger from running for certain users.  Anyone know what I'm doing wrong?

 

String userName = UserInfo.getUserName();

User activeUser = [Select Username From User where Username = : userName limit 1];

String Uname = activeUser.Username ;

for(Opportunity masterOppty:Trigger.new){

if(masterOppty.Related_Opportunity__c!=null && Uname!='a user name')

hisrinuhisrinu

Directly u can write like this

 

for(Account a : Trigger.New){

  if(Userinfo.getUserId != 'not user'){

    //Write your logic over here............. no need to query the user object

  }

}

Pradeep_NavatarPradeep_Navatar

Tryout the following :

 

            String userName = UserInfo.getUserName();

            User activeUser = [Select Username From User where Username = : userName limit 1];

            for(Account a : Trigger.New)

             {

                      if(activeUser != 'not user')

                      {

                             //Write your logic over here............. no need to query the user object

                       }

              }