You need to sign in to do that
Don't have an account?

How can i make a field readonly using trigger
Please any body help me how can i make a field readonly using triggers
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Please any body help me how can i make a field readonly using triggers
Check if the value of "readOnlyField__c" has changed like
if(trigger.new[0].readOnlyField__c != trigger.old[0]).readOnlyField__c)
{
trigger.new[0].addError('You can not change the value of readOnly__c');
}
But, I think you must keep triggers the last option(as they are difficult to maintain, compared to validation rules).
So, you can also achieve the same using some simple validation rules.
Agreed with Rahul,
You should be preferring Validation Rules or Page Layouts to make a field Read only rather than using Triggers to do the same.