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
nikki sharonnikki sharon 

hi guys im new to salesforce. i have been trying to do a trigger or validation rule to skip stage in opportunity in case that the checkbox is checked and i couldn't manage to do it. any ideas?

trigger
trigger skipStage on Opportunity (before update,after update) {
     if(opp.Customer_confirms__c== true && opp.StageName==       'Negotiation/Review'){
       opp.StageName = 'Closed won';
    }
     else{opp.StageName = 'Proposal/Price Quote';
        }

or validation rule 

IF(AND(Customer_confirms__c==true,
ISPICKVAL(PRIORVALUE(StageName),"Negotiation/Review")),
   ISPICKVAL(PRIORVALUE(StageName),"Closed won"),
   ISPICKVAL(PRIORVALUE(StageName),"Proposal/Price Quote"))
    
}
nikki sharonnikki sharon
instead of opp in the trigger i wrote opportunity of course. the opp left from another idea. thats not the problem
Maharajan CMaharajan C
Hi Nikki,

Don't use the validation rule for this scenario.

You have to write the trigger like below:

trigger skipStage on Opportunity (before update) {

    for(Opportunity opp : trigger.new)
        {
        if(opp.Customer_confirms__c == true && opp.StageName=='Negotiation/Review'){
           opp.StageName = 'Closed won';
        }
        else
        {
            opp.StageName = 'Proposal/Price Quote';
        }
    }
}

Thanks,
Maharajan.C
nikki sharonnikki sharon
hi friend:)
there is no error message but its still moving in the regular way between the stages, what i want is that if im doing checked so the next stage will be the last one. now its not doing anything.am i clear?
thank u so much for your help

User-added image
Maharajan CMaharajan C
Hi Nikkin,

For me it's working.

1. Check the trigger is Active.

2. The above code will works only in Opportunity Update. If you want this to work on Opportunity creation also then add the before insert in below line.
trigger skipStage on Opportunity (before insert ,before update) 

3. For existing records please simply edit the record once.


Thanks,
Maharajan.C