Thursday, 12 December 2013

How to get Picklist Value of an object Dynamically

This is very simple. I am sharing some code ,please go through this
Here is My Controller 
public class testclass {
    public Job__c job{get;set;}
    public List<SelectOption> options{get;set;}
    public testclass(){
        options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Job__c.Status__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple){
       
          options.add(new SelectOption(f.getLabel(), f.getValue()));
        }
    }
   
   
}

My Page 
<apex:page controller="testclass ">
  <apex:form>
      <apex:pageBlock>
          
          Order Status:<apex:selectList id="countries" value="{!job.Status__c}" size="1" required="true" >
              <apex:selectOptions value="{!options}"/>
          </apex:selectList>
      </apex:pageBlock>
      
  </apex:form>
  
</apex:page>

No comments: