+ Start a Discussion
Darshit Pathak 3Darshit Pathak 3 

What is the best way to throw error on some condition for all users except 27 user roles?

I want to make validation , but that error should not be thrown for users of pre defined 27 user roles.
What is the best way I can proceed with? 
- Hardcoding in validation rule?
- through apex (but where to store this list of roles, and in future if any modification required in the list, can it be configurable?)
Sunil RathoreSunil Rathore
Hi Darshit,

Greetings to you!

To make it dynamic/configurable using apex you can use Custom setting to store all these pre-defined roles which you can access in the Apex.
In future, if you want to add/remove then you can directly make changes in the Custom setting without making any changes in the code.

Please refer the below link for more details of Custom setting:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_customsettings.htm

Hope this will help you. If does then mark it as the best answer so it can also help in the future.

Many Thanks,
Sunil Rathore