How to Prevent Critical Data from Custom (addError) Validation using a Custom Label and Apex Trigger?
We know how important it is to have updated data of your customers. Often, we create validation in our site to get the customer details like name, email id, status, etc., in a proper format. But many times, we want to access critical information from our clients irrespective of whether it meets our criteria or not. So, in this smart solution, we will tell you how you can bypass those validation criteria to meet the critical information.
How does this solution work?
We have created a code in the custom trigger where a user can mark in the label the critical fields and need data anyhow. So, whether or not the data meets the validation criteria but it would let you have control over the critical data.
Hence, we have used a custom label to store critical field API names with comma(,) separation.
This trigger prevents updates on the Account record if an account is Inactive. But if critical fields are updated even if an account is inactive, then custom(adderror) validation is not fired.
Thus, making critical information updateable at any time.
Code
Trigger Code
Conclusion
With this simple piece of code, you have now achieved the unachievable! Preventing critical data from custom (addError) validation was never easier than this. We hope that you liked this simple blog and it was useful for you. We will be back with another blog soon to make your Salesforce experience smooth. Also, if you try out this solution for your business, share your valuable experiences with us. Till then, Happy Learning! 🙂