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 the 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. Also, note that using this to lock records is not a fool-proof solution as users will still be able to edit the record from the list view.
- 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 the desired condition raise an error. Triggers have two issues. One it is a custom development and second, the user will receive an error once they have made the changes and trying to save the record. Not a good option from the user’s 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 workflow 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.
NOTE: Certain sections of the guide will appear as locked in the free preview. You can download the unlocked version of the guide in PDF format by subscribing to our “All Access” Pass through the link below.