function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to restrict user to not to enter values or how to make field as readonly with help of trigger




Can anyone please share trigger code to restrict user to not enter values in the field as per condition.


 Its a bit urgent.


Prompt responses will be higly appreciated.


Thank you. 



lets say object is customObj__C and field is anyfield__c which we need to make not editable by user is there a condition met isRestricked__c is TRUE then
user following code. ( Here you can manupulate code according to your restricting condition)
for(customObj cobj : Trigger.New)

if(cObj.anyfield__c != Trigger.oldMap.get( && u.isRestricked == true )
Trigger.AddError('you are not allowed to do this');

You may write a validation rule on the USER object to achieve same