function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bharath SamanthulaBharath Samanthula 

Lock fields when a check box is checked

Hi, I would like to know how to lock a field when a check box is checked. the field i would like to lock has picklist values. I tried validation rule but its not working. Any help?
Best Answer chosen by Bharath Samanthula
Sagar PareekSagar Pareek
1. Validation rule : 
IF(checkbox__c==true && ISCHANGED(picklistfield__c))

2.Create a record type named locked picklist where you need to set the picklist field to read only(on the associated page layout), then write a trigger which will change the record type to locked picklist if checkbox is checked. 




 

All Answers

Sagar PareekSagar Pareek
1. Validation rule : 
IF(checkbox__c==true && ISCHANGED(picklistfield__c))

2.Create a record type named locked picklist where you need to set the picklist field to read only(on the associated page layout), then write a trigger which will change the record type to locked picklist if checkbox is checked. 




 
This was selected as the best answer
Sagar PareekSagar Pareek
You can go with any of these above ways.
Swayam  AroraSwayam Arora
So first of all, are you talking about Standard Detail Page or Visualforce Page.
1. Visualforce Page:- You can simply use Javascript, using 'onchange' event you can disable the picklist field.
2. Standard Page:- There can be 2 ways:-
    a. Write a validation rule formula as 'checkbox_field == true && ISCHANGED(picklist_field) '. In this case, visibly the picklist field won't be locked.
    b. Create one more Record Type and one more Page layout (keeping the picklist field as read only) and assign the Page layout to the Record Type. Write a workflow which will update the record type when the check box will be checked.
    First solution is preferable.

Please mark the answer as Best Answer if it really helped.
ra811.3921220580267847E12ra811.3921220580267847E12
Hi,

Write one validation :

trigger DemoCHK on Opportunity (before update) {

for(Opportunity opp:trigger.new)
{
if(opp.newCHK__c== true && (trigger.oldMap.get(opp.id).validatePickList__c!= opp.validatePickList__c))
{
opp.addError('RecordLocked');
}
}

}