Activity › Forums › Salesforce® Discussions › How to get the picklist value in Salesforce Apex class? › Reply To: How to get the picklist value in Salesforce Apex class?
MemberSeptember 19, 2018 at 12:30 pm
Lets say we have a custom object called OfficeLocation__c. OfficeLocation__c contains a number of fields, one of which is a picklist of country values called, creatively enough, Country__c. Our customer requirements are to include the picklist of countries on a Visualforce page which uses a custom controller. The first thing we need to do, within our controller is use the getDescribe() method to obtain information on the Country__c field:
Schema.DescribeFieldResult fieldResult = OfficeLocation__c.Country__c.getDescribe();
We know that Country__c is a picklist, so we want to retrieve the picklist values:
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
The only thing left for us to do is map the picklist values into an <apex:selectOptions> tag can use for display.
Hope this helps!