function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prince_sfdcPrince_sfdc 

getvalue() vs getLabel() in PickListEntry Class

what is the difference between the getValue() and getLabel() in PickListEntry Class, please explain with an example for each.
Best Answer chosen by Prince_sfdc
mritzimritzi
There are two parts to each picklist entry.
One is Value and the other one is Label.

getValue() -> gives you assigned value of a picklist entry
getLabel() -> gives you whats visible to the end user

In SFDC object fields, value and label components of Picklist entries are same. set that aside. (Fields like Country, Province, Opportunity StageName etc) 

The real significance IMO of value,label pair of picklist comes in VF/Apex.
Suppose you have a picklist in VF to display All existing Contacts. There can be more than one Contact Persons having same name. So when a user selects a entry from picklist, how would you know which record to handle?

This is where it all starts making sense. What developers do is that they store contact id as value and contact name as Label for each picklist entry.

Now, an end user sees Labels ie Contact Name, but when an entry is selected, its the value of the selected entry that's stored in Apex. which can be used to uniquely identified the contact record.

More info here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Schema_PicklistEntry.htm


Mark it as Best Answer, if it helps.

All Answers

mritzimritzi
There are two parts to each picklist entry.
One is Value and the other one is Label.

getValue() -> gives you assigned value of a picklist entry
getLabel() -> gives you whats visible to the end user

In SFDC object fields, value and label components of Picklist entries are same. set that aside. (Fields like Country, Province, Opportunity StageName etc) 

The real significance IMO of value,label pair of picklist comes in VF/Apex.
Suppose you have a picklist in VF to display All existing Contacts. There can be more than one Contact Persons having same name. So when a user selects a entry from picklist, how would you know which record to handle?

This is where it all starts making sense. What developers do is that they store contact id as value and contact name as Label for each picklist entry.

Now, an end user sees Labels ie Contact Name, but when an entry is selected, its the value of the selected entry that's stored in Apex. which can be used to uniquely identified the contact record.

More info here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Schema_PicklistEntry.htm


Mark it as Best Answer, if it helps.
This was selected as the best answer
Prince_sfdcPrince_sfdc
Yes, certainly it helped to clear the difference. Thanks :)