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
Manan_ShahManan_Shah 

Visualforce GUI design

Hi

 

I am creating page using Visualforce.

 

i have created input field like text box.

 

How can I create Select list so that all values of that list box coming from Salesforce custom object.

 

for example country is a select box and it has values like INDIA,USA,UK etc.

SwarnasankhaSwarnasankha

In your controller, create a method for fetching the list of records from the Country object. It should look something like this:

 

public List<SelectOption> getListOfCountry() 
{
  List<SelectOption> countryOptions = new List<SelectOption>();
  countryOptions.add(new SelectOption('','--None--'));
  for(Country__c countryName : [SELECT Name FROM Country__c ORDER BY Name LIMIT 10000])
  {
    countryOptions.add(new SelectOption(countryName.Name,countryName.Name));
  }
     
  return countryOptions;
}
With the method ready, you will need to display the list of queried country records as a select list and ensure that the selected value is pushed into the correct field at the object level. Try this:
<apex:pageBlockSectionItem>
<apex:outputLabel value="Country"/> 
<apex:actionRegion >       
<apex:selectList value="{!country}" multiselect="false" size="1"> 
<apex:selectOptions value="{!ListOfCountry}"/>
</apex:selectList>
</apex:actionRegion>  
</apex:pageBlockSectionItem>
The value parameter for the <apex:selectList> will reference the variable to which you would assign the value selected from the rendered dropdown.
Hope this helps.

 

Pradeep_NavatarPradeep_Navatar

If you are using standard controller in your page then you can bind the picklist field of your object to <apex:inputField/>. Suppose you have picklist field in your object(customObj__c) and api name is status__c, you can bind this field in page like,

 

<apex:inputField value=”{!customObj__c.status__c}” />

 

And if you are using custom controller the you need to first access the all values of that picklist field using schema of object. And then add these values to list of SelectOption type and bind in page like this,

 

Let the name of the list of selectOption type is myList.

 

<apex:selectList value=”{!selectedOption}”>

<apex:selectOptions value=”{!myList}”/>

</apex:selectList>