Sometimes you would want to lock records in Salesforce so that they can no longer be edited or deleted. When a record has reached the end of its lifecycle, nobody should be allowed to modify the record any longer. For example once an opportunity record is closed (closed won or closed lost), it just needs to live in system without being touched. Same can be for “Cases” or records sitting in your custom objects. Or maybe once a record has been interfaced to a backend system, you would want to lock the record so that it can no longer be modified in Salesforce.
So, then how do you lock records in Salesforce so that it can no longer be modified? Traditionally there has been a few options
- Using Record Type & Page Layouts: Create two different record types say “Open” & “Locked” and change the record type of the record using workflow field update or trigger. And then create a separate page layout for the “Locked” record type with all fields marked as ‘Read-Only’. Remove the ‘Edit’ and ‘Delete’ buttons from the page layout. However, this is not an option if you are using record types for some other purpose and do not want to change it just to meet this requirement.
- Using Record Ownership: Change the owner of the record using workflow field update or trigger and make sure that the OWD (Organisation Wide Default) and sharing rules are setup correctly to prevent updates or deletes. Again this may not be an option for you if you can’t change the record owners as it may have other impacts (e.g. reporting)
- Trigger: Write a trigger (before update, before delete) on the object and based on desired condition raise an error. Triggers have two issues. One it is a custom development and second, user will receive an error once they have made the changes and trying to save the record. Not a good option from user experience point of view
- Validation Rule: Write validation rule using ISCHANGED function. Here you will need to know for what all columns will you need to use the ISCHANGED function, and again users will receive error once they have made the changes and trying to save record
- Custom VF Page: Create custom Visualforce page and dynamically show/hide the ‘Edit’, ‘Delete’ buttons
I think, something like a worklflow action called ‘Lock/Unlock Record’ would have been quite handy for this.
But with Process Builder introduced in Winter 15 release, you now have an easier and more elegant way of locking records. Here is a step-by-step guide with screenshots on how you can achieve the same.