You need to sign in to do that
Don't have an account?
Mont Mont
My before Trigger is not before Validation Rule. Why?
I have a before insert, before update Trigger:
But I also have a Validation Rule for StageName 'B'. Trigger can't execute. Why? Before trigger must be before Validation Rule.
trigger OpportunityStageUpdate on Opportunity (before insert, before update) { for(Opportunity opp : trigger.new){ if(opp.StageName == 'A'){ opp.StageName = 'B'; } } }
But I also have a Validation Rule for StageName 'B'. Trigger can't execute. Why? Before trigger must be before Validation Rule.
Hey,
It seems when you execute this trigger, it successfully updates the stage name to B and then you have a validation rule on stage name which leads to the error.
A successful execution of before trigger is just an update on object Record, not the save or commit on the database.
In before trigger following step occur after the execution of beforeTrigger and validation rule .
"Saves the record to the database, but doesn't commit yet. "
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm