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
sfdeveloper12sfdeveloper12 

How to make picklist field read only?

Hello,

I want to make picklist field read only. There is no permission set. I make it read only from page layout, Field level security and profile too. Still its read only. What will be another option to make it rad only?

Thanks & Reagrds,
Utkarsha
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Utkarsha Patil,

Visualforce Page:
<apex:page standardController="Account" extensions="AccountExtensionController">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection>                
                <apex:inputField value="{!acc.Name}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection>                
                <apex:inputField value="{!acc.AccountSource}" rendered="{!NOT(isSaved)}"/>
                <apex:outputField value="{!acc.AccountSource}" rendered="{!isSaved}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>  
    </apex:form>
</apex:page>

Controller Extension:
public class AccountExtensionController {

    public Account acc {get; set;}
    public Boolean isSaved {get; set;}
    
    public AccountExtensionController(ApexPages.StandardController controller) {
        acc = (Account) controller.getRecord();
        isSaved = false;
    }

    public PageReference save() {
        insert acc;
        isSaved = true;
        return null;
    }
}

I hope it will be helpful.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
sfdeveloper12sfdeveloper12
Hi rahul,

I am not doing it on VF page.

Thanks & Best Regards,
Utkarsha
sfdeveloper12sfdeveloper12
Actually i am having approval process which checks one of the value in this picklist field.
For Eg. If Approval Status = Awaiting for approval then it fires an approval process.
I am doing it on quote object. When quote line item and discount changes then i update Approval Status field = "Awaiting for approval". So i need to change this picklist field using trigger thus i can not use ischange(field) validation rule
Ahmad J. KoubeissyAhmad J. Koubeissy
why you dont just make it read only on the layout, and you will be able to change it in the trigger. you can use the ischanged. what is the problem exactly ?
sfdeveloper12sfdeveloper12
Hi Ahmad,

I make it read only from page layout, field level security and owd. Still its editable. Now, i have removed it from page layout and created one formula filed which displays picklist value based on the criteria in trigger and workflow rules.

Thanks & Regards,
Utkarsha
Shilpa SrikantacharShilpa Srikantachar
@sfdeveloper12/Utkarsha , can you share the formula you are using?