I have situation here, where I want to lock all the fields and buttons on a quote__c (custom object) where the status of the quote is changed to 'Sent' so that nothing can be editable on the quote.

Any ideas how to do this?

  • If you want to lock the records when specific citeria meet the records use Apex coding like for update.@Shweta Soparkar – Pavan tej Jul 26 '16 at 15:08
  • 1
    There are multiple declarative methods that you could leverage to lock all fields on an object under certain conditions without the need for Apex coding @Pavantej - Workflow rules/Record Types, Validation Rules, even Approval Rules. – Morgan Marchese Jul 26 '16 at 15:42

As Robin mentions in his answer, this could be done via Page Layouts and Record Types, but I'd like to expand on that and give you some options and considerations:

Option A - Record Types/Page Layouts - UI Level Security:

  1. 2 Record Types

    • Unlocked (Default)
    • Locked
  2. 2 Page Layouts

    • Unlocked Layout (Assigned to Unlocked Record Type)
    • Locked Layout (Assigned to Locked Record Type)
      • (This layout would have all fields Marked as Read Only, and you could even go as far as removing the action buttons for edit/delete/etc)
  3. A Workflow rule that sets the Record Type to the "Locked" type when it meets your criteria.

2 Considerations for this approach:

  1. This is only viable IF all of the fields you want to stop a user from editing can be marked as "Read Only" on the Page Layout level. In some cases, some fields may be required and cannot be set to Read Only

  2. Since this is only marking the fields as Read Only on the UI/View Level, it isn't actually guaranteeing that these records cannot be changed. These fields could still be changed via Workflows, Processes, DML Updates, Data Loader, or other API calls. If you need to completely lock down modification on the Data/Model level, you should consider Validation rules (see below)

Option B - Validation Rule - Data Level Security:

You could also create a Validation Rule that is fired if any field is Changed (including if they attempt to change your Status == Sent field to dodge the VR), and inform them that they cannot make any changes since the Quote has already been sent.

Example (This is a VR I have on our Event object):

    ISPICKVAL(PRIORVALUE(Status__c), 'Completed'),


2 considerations for this approach:

  1. This will block ALL changes from ANYONE regardless of method (WFR, Apex, API, etc) - The VR can be modified to expand access, allow the VR to be bypassed by certain Users/Profiles, and even to incorporate checks that will still allow automation to pass if you want to get very advanced) - But at its core without any modification, a VR like this would block ALL changes to the record after being marked as 'Sent'
  2. If you add additional fields to your object, you would need to remember to come back and edit this VR every time if you also wanted to block editing of those new fields.

Option C - Apex - Data Level Security:

Option C is to code some custom apex validation rules, but I recommend avoiding this where possible - Validation Rules are easier to maintain by standard Administrators than a custom apex VR would be. However you could also go the Apex route if Option A and B don't fit the needs of your business.

  • I tried the Option 1 and it worked perfectly but the fields which are required are still editable as I am not even to make those read only. – Shweta Soparkar Jul 28 '16 at 15:41
  • Hey @ShwetaSoparkar - That's one of the downfalls of Option 1, because you can't make a field Read Only if it is also Required, and some fields are required by default. You could still use Option 1 but then also use Option 2 and create a Validation Rule that stops your users from changing the required fields when set to a specific status. My example in Option 2 should help you get started – Morgan Marchese Jul 28 '16 at 18:23
  • Yes thats what I was thinking about. It will be good to have a validation rule to prevent the users from changing anything even if the field looks editable. – Shweta Soparkar Jul 28 '16 at 20:50
  1. Create 2 record types on quote: eg. 'Unlocked' and 'Locked'
  2. Default record type would be unlocked with your regular page laoyut assigned to it
  3. Create a workflow that updates the record type to 'Locked' once the status reaches 'Sent'
  4. Create a specific page layout where you make all fields read-only and remove all buttons, and assign to the 'Locked' record type
  • Great suggestion that I have used a few times in my organization across many objects. As long as all of the fields you are trying to protect can be marked as "Read Only" then this is a simple approach. If however there are some fields that you want to block from changing that are also Required fields that cannot be removed from the layout, this may not work 100%. – Morgan Marchese Jul 26 '16 at 15:45
  • Yup you are right that's why i thought coding is better because i face the situation like in lead about company field.But it depends on the requirement as the administrator point of view record types is better approach. @Morgan Marchese – Pavan tej Jul 26 '16 at 15:49
  • @MorganMarchese All true of course, but this was not mentioned in the question. It says a custom object, so I was assuming no standard special behavior fields. Your answer is definitely more complete. – Robin De Bondt Jul 26 '16 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.