[SalesForce] when to use validation rule & trigger’s add error method

what is the difference between validation rule & triggers add error method? mens when I can use validation rule & when use adderror method?

Best Answer

You can use either to achieve the same effect. It's usually more a matter of preference. If you can use a validation rule, you should, but if the validation rule would be too complicated, or impossible to write (such as checking unrelated records for data), then use Apex Code. We generally call this the "configuration before code" rule of thumb. However, there are some times when using code instead of validation rules are helpful, like if you want to disable the validation via code to bypass the logic when updating records in code.

Related Topic