+ Start a Discussion

How to make a record read only through coding not through sharing rules

How to make a record read only through coding not through sharing rules

Imran MohammedImran Mohammed



Anyhow your question does not have more details. I will answer it as per  my understanding.

Please let me know if this is what you were looking for.


From the code whichever object you are trying to update or any other DML operation, do the following.

Schema.DescribeSobjectResult dsr = <<Object>>.sObjectType.getDescribe();

Then check whether this object is updateable or whatever you are trying to perform.

if(dsr.isUpdateable()){Code that performs DML}

If true then you can allow operation to perform else you can bypass the DML code.


In this way you can make that record read only.


Let me know if this is what you were looking for or if its not clear.








There are two ways:


1) Use validation rules that will apply only for updates (Use NOT(ISNEW()) to check for update). Use the functions available to verify the conditions for read-only. (much preffered method)



2) Use before update trigger. In trigger if your condition for read-only meets, then use


trigger.new[i].addError('Insufficient Priviliges');


the addError will prevent any DML actions (update) on record since it a before trigger.


Note: this should only work for "before update" after update is not going to work. Also if you want to avoid coding, you can use Validation rules. If possible give first preference to point and click (Validation rule) rather than coding.


There may be another way as well which may offer a better user experience. Are you looking to "lock" a record from being editable across the board or just read only for a subset of users?


can you let us know how do i lock a record across the board using point and click tools or code?




It's a combination of clicks and code actually.  It involves creating an approval process for the record which locks the record on "submission" which you can automate with code. Likewise you can automate the unlocking, i.e. approving/rejecting as appropriate.