The only thing left for us to do is map the picklist values into an <apex:selectOptions> tag can use for display. Here is the entire method from our controller to do this: public List<SelectOption> getCountries() { List<SelectOption> options = new List<SelectOption>();
With our controller logic all complete, we can call the getCountries() method from our Visualforce page, and populate the <apex:selectList> tag: <apex:selectList id="countries" value="{!Office_Location__c.Country__c}" size="1" required="true"> <apex:selectOptions value="{!countries}"/> </apex:selectList>
Using Dynamic Apex to retrieve Picklist Values
https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
The only thing left for us to do is map the picklist values into an <apex:selectOptions> tag can use for display. Here is the entire method from our controller to do this:
public List<SelectOption> getCountries()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =
OfficeLocation__c.Country__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
With our controller logic all complete, we can call the getCountries() method from our Visualforce page, and populate the <apex:selectList> tag:
<apex:selectList id="countries" value="{!Office_Location__c.Country__c}"
size="1" required="true">
<apex:selectOptions value="{!countries}"/>
</apex:selectList>
Example 2:-
http://www.forcetree.com/2009/06/dynamically-add-values-to-picklist.html
https://www.minddigital.com/how-to-create-dynamic-dependent-picklist-of-objects-within-salesforce/
Let us know if this will help you
Thanks
Amit Chaudhary