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
srikanthpallasrikanthpalla 

How we will create list box fields in slesforce

HI

Any one let me know how we will create list box fields in salesforce.please explain
Best Answer chosen by srikanthpalla
Mehul MakwanaMehul Makwana
Hi,

If you want to create Listbox in Visualforce page then you can refer below code

Visualforce Page Code:
<apex:form > 
    	<apex:pageBlock >    
            <apex:pageBlockSection >
            	<apex:selectList value="{!country}" label="Country" multiselect="false" size="1">
                    <apex:actionSupport event="onchange"/>
                        <apex:selectOptions value="{!countryOptions}"/>
                </apex:selectList>
            </apex:pageBlockSection>            	
        </apex:pageBlock>
    </apex:form>

Controller Class:
 
public class CountryStateController 
{
    public String country{get;set;}
    
    public CountryStateController(){
        
    }
    
     public List<SelectOption> getcountryOptions() 
     {
            List<SelectOption> countryOptions = new List<SelectOption>();        
             
            countryOptions.add(new SelectOption('India','India'));
            countryOptions.add(new SelectOption('USA','USA'));
            countryOptions.add(new SelectOption('Japan','Japan'));
  
            return countryOptions;
     }
}
Let me know if it works for you!
 

All Answers

Mehul MakwanaMehul Makwana
Hi,

If you want to create Listbox in Visualforce page then you can refer below code

Visualforce Page Code:
<apex:form > 
    	<apex:pageBlock >    
            <apex:pageBlockSection >
            	<apex:selectList value="{!country}" label="Country" multiselect="false" size="1">
                    <apex:actionSupport event="onchange"/>
                        <apex:selectOptions value="{!countryOptions}"/>
                </apex:selectList>
            </apex:pageBlockSection>            	
        </apex:pageBlock>
    </apex:form>

Controller Class:
 
public class CountryStateController 
{
    public String country{get;set;}
    
    public CountryStateController(){
        
    }
    
     public List<SelectOption> getcountryOptions() 
     {
            List<SelectOption> countryOptions = new List<SelectOption>();        
             
            countryOptions.add(new SelectOption('India','India'));
            countryOptions.add(new SelectOption('USA','USA'));
            countryOptions.add(new SelectOption('Japan','Japan'));
  
            return countryOptions;
     }
}
Let me know if it works for you!
 
This was selected as the best answer
srikanthpallasrikanthpalla
Thank you Mehul Makwana