+ Start a Discussion
Surender reddy SalukutiSurender reddy Salukuti 

how can i by pass validation rule using apex?

Hi all ,

i have one requirement i need to by pass one validation rule for particular users  by using apex class how can i do that .


Thank you 

Surender Reddy

Hii Surrender
Try Below Code
trigger validphonemust on Account(before insert)
Id profileId=userinfo.getProfileId(); 
String profileName = [Select Id,Name from Profile where Name = 'Office Profile'].Id;
  for(Account a : trigger.new)
    if(a.phone=='' || a.phone==null){
      If(profileId == profileName ){
      a.addError('Phone number must');
Please Mark It As Best Answer If It Helps
Thank You!