+ Start a Discussion
PrakkiPrakki 

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

 

Hello,

 

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. 

 

sandeep@Salesforcesandeep@Salesforce

Hi
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(cobj.id).anyfield__c && u.isRestricked == true )
{
Trigger.AddError('you are not allowed to do this');
}
}

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