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
Wahid BuhariWahid Buhari 

picklist should show only one value

Hi,
I am using apex:inputfield to show  picklist values in a VF page. The picklist has various values say A, B, C. But I would like to show only A in my vf page without removing B and C from picklist. Are there any ways to acheive this?

Thanks,
Wahid
Best Answer chosen by Wahid Buhari
Dinesh MultaniDinesh Multani
Use below code 

VF page- 
<apex:page Controller="AccController" >
<!--Using controller as I'm assuming you will be rendering value through some logic-->
    <apex:form >
       <!--Input text to display a single value from the picklist-->
        <apex:inputtext value="{!acc.type}" />
    </apex:form>
</apex:page>

Apex Class-
public class AccController {
    
    public account acc{get;set;}
    public AccController() {
       //Querying through Account just for your reference your logic can be implemented to display values here
        acc= [Select type from Account limit 1];
    }
}



 

All Answers

Dinesh MultaniDinesh Multani
Use below code 

VF page- 
<apex:page Controller="AccController" >
<!--Using controller as I'm assuming you will be rendering value through some logic-->
    <apex:form >
       <!--Input text to display a single value from the picklist-->
        <apex:inputtext value="{!acc.type}" />
    </apex:form>
</apex:page>

Apex Class-
public class AccController {
    
    public account acc{get;set;}
    public AccController() {
       //Querying through Account just for your reference your logic can be implemented to display values here
        acc= [Select type from Account limit 1];
    }
}



 
This was selected as the best answer
Wahid BuhariWahid Buhari
@Dinesh Multani Thank you so much. It did work!