Posts

Showing posts from March, 2017

Get Picklist Values Using Dynamic Apex

Image
  The picklist field name and object are the two parameters that the code snippet below requires. We can read either the Picklist label or the value based on these two inputs. String objectName = 'Account'; String fieldName ='Industry'; Schema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ; Schema.DescribeSObjectResult r = s.getDescribe() ; Map<String,Schema.SObjectField> fields = r.fields.getMap() ; Schema.DescribeFieldResult fieldResult = fields.get(fieldName).getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ System.debug(pickListVal.getLabel() +' ---- '+pickListVal.getValue()); }