Sunday, April 5, 2015

Get the Picklist Values by using sObject Describe call in Apex

// Contains all Account.Industry values
Set<String> IndustryValues = new Set<String>();

// Get Account.Industry values from the field on Account object
Schema.DescribeFieldResult accountIndustry = Account.Industry.getDescribe();

List<Schema.PicklistEntry> accountIndustryValues = accountIndustry.getPicklistValues();        
for(Schema.PicklistEntry industryValue: accountIndustryValues){

System.Debug('>>Account Industry Values<<'+IndustryValues);

Result should be as follows

>>Account Industry Values<<{Agriculture, Apparel, Banking, Biotechnology, Chemicals, Communications, Construction, Consulting, Education, Electronics, ...}