Get picklist values in apex

 We can get picklist values and their labels in apex.


***

//get picklist values

    public static void getPicklistValues(){

        Map<String, String> pickListValuesMap = new Map<String, String>();

        Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();

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

        for( Schema.PicklistEntry pickListVal : pEntry){

            pickListValuesMap.put(pickListVal.getValue(),pickListVal.getLabel());

        }     

        System.debug('pickListValuesMap ##'+ pickListValuesMap);

    }


By using this method you can get any picklist values from any object(Standard or Custom).

***

Comments

Popular posts from this blog

Get current user information in apex

Show only DML exception message from parent exception