Saturday, July 13, 2019

Getting picklist field options in list in apex classs

Display pick list values in your custom page through dyanamic apex .You can check below link it will help  .

https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html

If you want in a string array or list then you can use below code .

public List getPickListValuesIntoList(){
       List pickListValuesList= new List();
  Schema.DescribeFieldResult fieldResult = ObjectApiName.FieldApiName.getDescribe();
  List ple = fieldResult.getPicklistValues();
  for( Schema.PicklistEntry pickListVal : ple){
   pickListValuesList.add(pickListVal.getLabel());
  }     
  return pickListValuesList;
    }