Skip to main content
Abhilash Mishra (Accenture) 님이 #Apex에 질문했습니다
Hi, 

can i get all the values of a picklist field in a list some how?

I have picklist type custom field in the product. having some options.

In my apex class i want to use these options. can I get them some how throught code? 
답변 9개
  1. 2016년 2월 3일 오후 12:03
    Hi Abhilash,

    If you want to 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<String> getPickListValuesIntoList(){

    List<String> pickListValuesList= new List<String>();

    Schema.DescribeFieldResult fieldResult = ObjectApiName.FieldApiName.getDescribe();

    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

    for( Schema.PicklistEntry pickListVal : ple){

    pickListValuesList.add(pickListVal.getLabel());

    }

    return pickListValuesList;

    }

    Let us know if it helps !!

    Thanks

    Manoj