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
ExploreForceExploreForce 

To skip validation rule for Users in PermissionSets

trigger OpportunityBeforeUpdate on Opportunity (before update) {

    //Update Account Global account
  
    List<Opportunity> listOpp = new List<Opportunity>();
    
       if(trigger.isBefore)
      {
      
         if(Trigger.isUpdate)
         {
         
            for(Opportunity fOpp: trigger.new)
               {
                 if(fOpp.StageName != trigger.oldmap.get(fOpp.Id).StageName)
                     listOpp.add(fOpp);
               }
         
         }
      }
      
        //list<PermissionSet> lstPermissionSets=[Select Name,Id From PermissionSet where Name='Opportunity_Users_Permission_sets'];
        list<PermissionSetAssignment> lstPermSets=[select PermissionSet.Name from PermissionSetAssignment
                                                   where Assignee.Id = :UserInfo.getUserId()
                                                   AND PermissionSet.Name='Opportunity_Users_Permission_sets'];
       system.debug('>>>>>>>lstPermSets>>>>'+lstPermSets);    
       if(lstPermSets.size()>0 && listOpp.size()>0)
       {
           
           Opportunity nOpp=[select Id,SkipStage__c,StageName from Opportunity where Id=:listOpp];
           system.debug('>>>>>>>Opportunity STAGE CHNAGE>>>>');
           //nOpp.SkipStage__c= true;--I need to set(boolean) this to true to skip validation.
           //update nOpp; 
       
       }


Please anyone can suggest, how to skip validtion rule for users in permissionsets .
Vijay NagarathinamVijay Nagarathinam
Hi
We can't skip the validation rule, because the order of execution is first before trigger fired then validation rule will be fired.

So add the validation rule functionality in your apex trigger.

For your reference https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

I think it will be helpful for you.