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

Popular Post

Find Day of selected Date on VF Page

How to Calculate Sum of Amount and Pass Date Value in Url

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 401