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
Mont MontMont Mont 

My before Trigger is not before Validation Rule. Why?

I have a before insert, before update Trigger:
trigger OpportunityStageUpdate on Opportunity (before insert, before update) {
    for(Opportunity opp :{
        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.
Tejender Mohan 9Tejender Mohan 9

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. "