0

I am aware of the order of execution. But I am bit confused for the following scenario. I have a validation rule on the number field like number should be less than 10000. Now I have a workflow field update and it is updating with 15000. Now user has entered 12000. What will happen in this case? what will happen if we replace validation Rule with before trigger? Will the record be not saved in the both cases?

3
  • In your example the VR will never fire.... neither 15k nor 12k are less than 10k Jan 24 '20 at 17:28
  • 1
    Validation rule is getting fired when i entered 12k . as the entered no is greater than 10k. Please correct me if m wrong?
    – user78290
    Jan 24 '20 at 17:42
  • I misunderstood your use case, then. sfdcfox has the right answer. Jan 24 '20 at 18:28
4

If the user enters 12,000, but the Validation Rule means that the limit is 10,000 or less, the rule would stop the user from even getting as far as the Workflow Rule Field Update. If the user enters a value of less than 10,000, and the Workflow Rule Field Update sets the value to 15,000, this will be allowed. Validation Rules don't run after Workflow Rules. A trigger that checks for a value of less than 10,000 would block the Workflow Rule Field Update from occurring, because they do execute after a Workflow Rule Field Update.

0

Validation rules will prevent the record from saving if the formula evaluation value is true.

In your case if this number field is less than 10000, the validation will prevent the record from saving.

If you replace the VR with a before trigger on the object, that will prevent from saving too. just remember to add to the record an error, for example:

for (MyObject obj : Trigger.new) {

if (obj.numberField < 10000) obj.addError('numberField must be greater than 1000');

}

Note: In case your record is coming from another update transaction the before trigger validation will be executed one more time, as opposed the validation rule it won't, validation rules only run onece for the first update transaction

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.