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
Krishna Singh 22Krishna Singh 22 

User Trigger and User Validation rules firing in different transactions

Hi Everyone,

I am trying to create a User Trigger that has a before insert operation which is supposed to bypass a Validation Rule. But both the validation rule and the Trigger are running in different transactions, hence the validation rule is firing. Please refer below snapshot of Debug Logs:
User-added image
I think this has something to do with User object being a Setup Object(although i was unable to find documentation for the same).
Dhanya NDhanya N
Hi Krishna,

The order of execution is first before triggers and then validation rules. If you want to by pass the validation rule, then you have to make changes in validation rule criteria too.
You can follow the approach mentioned in this link : https://salesforce.stackexchange.com/questions/3392/how-to-bypass-validation-logic-in-a-trigger

Thanks,
Dhanya
Krishna Singh 22Krishna Singh 22
Hi Dhanya,
Thanks for the answer.
This is the scenario:
Let's suppose there is a field Field1__c that should not be blank according to the validation rule. But i am setting the field in the before trigger. Still it is giving me the error. If i try the same approach in any other object except User, it works well. But in User object trigger is running in a different transaction(asynchronously) hence the validation rule fires asynchronously to the trigger execution and does not follow the flow of execution.