How to get picklist values of Standard object picklist?

Sample code:

Visualforce page:

<apex:page Controller="sample">

<script type="text/javascript">

</script>
   
    <apex:form >
   
    <apex:pageMessages />
   
    <apex:pageBlock >
        <apex:pageBlockSection columns="2">
            <apex:pageblockSectionItem >
                <apex:outputLabel value="Ownership"/>
            </apex:pageblockSectionItem>       
            <apex:pageblockSectionItem >
                <apex:selectList value="{!ownership}" size="1" >
                    <apex:selectOptions value="{!ownershipOptions}"/>
                </apex:selectList>               
            </apex:pageblockSectionItem>           
        </apex:pageBlockSection>       
    </apex:pageBlock>

    </apex:form>

</apex:page>


Apex Controller:

public class sample
{   
    public String ownership {get;set;}
     
    public sample()
    {
       
    }

    public List<SelectOption> getownershipOptions()   
    {   
        List<SelectOption> options =  new List<SelectOption>();   
        options.add(new selectOption('None','--- None ---'));   
        Schema.DescribeFieldResult fieldResult = Account.ownership.getDescribe();   
        List<Schema.picklistEntry> ple = fieldResult.getPicklistValues();   
        for(Schema.picklistEntry f:ple)   
        {   
            options.add(new selectOption(f.getLabel(),f.getValue()));                   
        }   
        return Options;   
    }     
}



No comments:

Post a Comment