Get Picklist Value Using Describe Call on VF Page
Requirement: Get Contact Salutation on VF page
Class Code
public Contact objcontact {get;set;}
public List<SelectOption> getContactSalutations()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('','---None---'));
//For fetching Picklist Values
Schema.DescribeFieldResult fieldResult =
Contact.Salutation.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(),f.getLabel()));
}
System.debug(options);
return options;
}
Page Code
<apex:selectList multiselect="false" size="1" value="{!objContact.Salutation}">
<apex:selectOptions value="{!ContactSalutations}"/>
</apex:selectList>
SnapShot
Comments
Post a Comment