1

I would like to get label of stored picklist value. Is there any straight forward way of doing that or I have to loop through all picklist values?

1
  • I suspect you will have to loop through to get it. Might be an idea to store the label on a hidden field to save yourself repeated processing. Nov 16 '12 at 4:11
6

For picklist values you can use the toLabel() function in soql to retreive the label, e.g.

select select id,name, toLabel(Industry) from account

Otherwise you can call describeSobject and get the label from the returned picklistValue structure.

0

You may Use Custom settings to store the Labels if you think looping may bring issues.Have a custom Setting with api name and label and you may use custom setting methods to retrieve only for those you want.

Map mapCodes = ISO_Country__c.getAll();
// display the ISO code for Afghanistan
System.debug(‘ISO Code: ‘+mapCodes.get(‘AFGHANISTAN’).ISO_Code__c);
2
  • The "custom setting approach" screw you up so hard as soon as a requirement to get the translated labels will pop up ;) Cust. Labels would be better...
    – eyescream
    Nov 16 '12 at 7:07
  • Ah great point !!Yes if multilingual custom labels are preferred Nov 16 '12 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.