1

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

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

  • You might need to post some code in order to get better understanding. In general, for any object the before trigger are running before validation rule. Therefore if trigger set the field, then the validation should not show you error – Liron C Mar 22 '18 at 9:24
0

This only affects the user interface.

Testing this in my org, in the UI, I get this log:

02:25:58.2 (2063936)|EXECUTION_STARTED
02:25:58.2 (2128116)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:User:005XXXXXXXXXXXX
02:25:58.2 (2201994)|VALIDATION_RULE|03d50000000bliW|required_is_required
02:25:58.2 (2380120)|VALIDATION_FORMULA|NOT(Required__c)|Required__c=0
02:25:58.2 (2467231)|VALIDATION_FAIL
02:25:58.2 (2608795)|CODE_UNIT_FINISHED|Validation:User:005XXXXXXXXXXXX
02:25:58.2 (2618194)|EXECUTION_FINISHED

But when I use the API or Execute Anonymous, I get:

02:29:05.3 (3551601)|EXECUTION_STARTED
...
02:29:05.3 (7421512)|DML_BEGIN|[1]|Op:Update|Type:User|Rows:1
...
02:29:05.3 (60344718)|VARIABLE_ASSIGNMENT|[3]|this.Required__c|true|0x76dba5c
...
02:29:05.3 (75909697)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:User:005XXXXXXXXXXXX
02:29:05.3 (75947702)|VALIDATION_RULE|03d50000000bliW|required_is_required
02:29:05.3 (76423313)|VALIDATION_FORMULA|NOT(Required__c)|Required__c=1
02:29:05.3 (76441212)|VALIDATION_PASS
02:29:05.3 (76510814)|CODE_UNIT_FINISHED|Validation:User:005XXXXXXXXXXXX
...
02:29:05.3 (121745861)|EXECUTION_FINISHED

I suspect that this design is in place from a UI perspective because updates can take significant time, so if it continues beyond a couple of seconds, the user won't need to wait while sharing rules are recalculated, etc. There are a few pages in Setup that do this, and almost all of them revolve around showing a spinner while a significant (potentially hours-long) process kicks off, such as creating, updating, or deleting sharing rules, users, and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.