2

I know that you can get all label names of picklist with the following code.

Schema.DescribeFieldResult fieldResult = Account.PicklistField__c.getDescribe();
List<Schema.PicklistEntry> values = fieldResult.getPicklistValues();

for( Schema.PicklistEntry v : values) {
      System.debug('Picklist Value Label:' + v.getLabel());
      System.debug('Picklist API Name:' + v.getValue());
}

Is there a way to get just the label of the specified API reference name? In addition to the following

Schema.DescribeFieldResult fieldResult = Account.Ownership.getDescribe();
List<Schema.PicklistEntry> values = fieldResult.getPicklistValues();

String result;
for( Schema.PicklistEntry v : values) {
//    System.debug('Picklist Value Label:' + v.getLabel());
    System.debug('Picklist API Name:' + v.getValue());
    if (v.getValue() == 'public') {
        result = v.getLabel();
    }
}
0

1 Answer 1

3

There is no direct way but you can put all the values in a Map<value,label>. Then just use Map.get('public')

Map<String,String> MapValueLabel = new Map<String,String>();
String publicLabel;

for( Schema.PicklistEntry v : values) {
    MapValueLabel.put(v.getValue(),v.getLabel());        
}

publicLabel = MapValueLabel.get('public');
1
  • No problem. Mark the answer as 'Accepted' if it works for you.
    – sfdcFanBoy
    Commented Jan 10, 2018 at 6:32