I am using SOQL to query the opportunity. When I use the query,
SELECT CUSTOM_PICK_LIST_COL__C FROM OPPORTUNITY
I am getting the values under the API Name of the picklist items. How to get the value from the Values of the picklist?
You can use toLabel()
to convert the picklist api name to a label:
SELECT toLabel(CUSTOM_PICK_LIST_COL__C) FROM OPPORTUNITY
You don't need to use SOQL
to do this, instead you can get it using Apex
's Schema
utility and DescribeFieldResult
class. For example:
public List<String> myPicklist {
get {
if (myPicklist == null) {
myPicklist = new List<String>();
Schema.DescribeFieldResult field = Object__c.MyPicklist__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
myPicklist.add(f.getLabel());
}
return myPicklist;
}
set;
}
This just returns a List<String>
of labels of the field MyPicklist__c
in object Object__c
.
You might want to review what you can do with that class here.
Bonus: you don't use any SOQL
and contribute to limits.
SOQL
to get Picklist values, but that doesn't mean that you should. It's nice to put both answers on the table though. :) +1!
Commented
Mar 2, 2017 at 13:00
SOQL
query. Instead you can do that using Apex