+ Start a Discussion

how to lock a record via apex

I can lock a record via Approval Process .. I want to also lock a record if Status__c == 'Live' .. can I do that via apex?? 

On the other hand how does SF locks a record?? I do not see any standard-lock-field in the objects ?? 


There is no such field.  But you can make a validation rule that disallows edits if that field is selected, or you can make a record type such that when that field is selected in that way, the record type makes all fields read only in the page layout (you'd need a workflow to change the record to that record type when the field were selected in that manner).


I do not want user to hit edit and enter the details and get bumped with error message when tries to save the changes. 

I want something that tells user upfront that the record cannot be edited, just like when a record is locked. 

James (CloudAnswers)James (CloudAnswers)

You could override the edit page with a page/class that checks if the user is allowed to edit, then send them to the edit url with "?noredirect=true" on the end of the url.


Thanks for the reply .. I have already overridden the edit button, so no issues there. 

But users are tech savvy and they might enter /e at the end of the url to go to the edit page.. nothing stops them from doing that..