I have contact and one picklist field on contact. If picklist values is 'Read' then no one should edit the record and if he tried to edit and save then error needs to be thrown 'You are not allowed to edit' while saving the records.
2 Answers
You can add validation rule like
ISPICKVAL(PicklistField__c, 'Read')
If you want to skip this for particular users or profile you can do that by adding exception like
ISPICKVAL(PicklistField__c, 'Read') && $Profile.Name != "SomeProfile"
If you want to skip this for Apex/System mode then you need to create one more checkbox field(Is_Validation_Exempt__c
) and validation rule like
Is_Validation_Exempt__c == false && ISPICKVAL(PicklistField__c, 'Read') && $Profile.Name != "SomeProfile"
then set Is_Validation_Exempt__c = true
from apex and make it false by workflow when it is true.
Note : Is_Validation_Exempt__c field should be hidden from all users.
In addition to Rahul's answer I will add a couple more possibilities:
- Create a "Read-only" record type, page layout with all fields as "Read-only" and set the contact's record type in a trigger/process.
- Dirty way: add a check in a trigger and use
.addError()
method to block the updates