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
Narayan HNarayan H 

How can I make fields Conditionally Read-Only - based on a picklist value

Can someone help me get moving with some data validation please?

I would like to set a field as being conditionally read-only based on the value of a picklist. What I have is a picklist that shows the specific Account type. Based on that selection I would like to have some fields red-only so that I can enforce some level of process control.

I really appreciate your help in this regard.
pconpcon
The only way to do this is with VisualForce.  You will have to have code in your controller that determines if the field is an outputfield (read only) or an inputfield (read / write).  Then you'll need to call a reRender on the fields on change the dropdown.  This blog post may give you some help for this.

http://blog.deadlypenguin.com/blog/2012/07/09/dynamic-dependent-picklists-in-salesforce/
SarfarajSarfaraj

This is possible using custom code and Visualforce page.

However if you want to go with the configuration you have to use validation rules. You have to configure a validation rule to validate if the picklist value is some value say 'A' then the fields under consideration should match with their prior value.

I have configured one with this logic: If the Account Rating is 'Hot' you cannot change the Account Number and Name. Here is the validation rule,
User-added image

--Akram
Suraj Tripathi 47Suraj Tripathi 47
Hello Narayan

Suppose Account has One field which name field1 is picklist type then you can use this trigger :
you can use this trigger :
trigger conditionRating on Account (before update) {
    for(Account acc : trigger.old){
        If(acc.field=='something'){            
                Acc.AddError('Cannot Change rating');
              }
        }
}

you can get references from this :
https://salesforce.stackexchange.com/questions/170716/making-a-field-as-un-editable-conditionally
-----
If you find your Solution then mark this as the best answer

Thank you!

Regards,
Suraj Tripathi
Carol Ann HultmanCarol Ann Hultman
If you are using Lightning pages... I think you could add the field to the page twice, one read only and one editable field an then show and hide those fields based on the criteria.  Hope this helps!

Kindly,
Carol-Ann