Sub topic 7
Picklists, Multi-Select Picklists and Global Value Sets
This chapter covers the picklist family of field types. It assumes you know what objects, records and fields are, and that you can find a field in Object Manager. You should also know the difference between a standard and a custom field. Picklists limit what users can enter, but they carry several side effects that are easy to miss. These include formula syntax, reporting limits and how values behave in code.
What a picklist stores
A picklist field stores one value from a list that an administrator defines. A multi-select picklist stores several values from the list in a single field. Both types protect data quality, because users choose a value instead of typing free text. Reports can then group records without cleaning up spelling variants.
Apex sees these types as PICKLIST and MULTIPICKLIST. Standard fields such as Account.Type are picklists too.
| Feature | Picklist | Multi-select picklist |
|---|---|---|
| Values per record | One | Several |
| Stored as | The selected value as text | Selected values joined by semicolons |
| Formula comparison | `ISPICKVAL` | `INCLUDES` |
| Usable in a report grouping | Yes | Limited |
| Controlling field for dependencies | Yes | No |
| Can be a dependent field | Yes | Yes |
Defining values
Each picklist has a list of values, and each value has a label and an API value. For a custom picklist these start out identical. A value can be active or inactive. You can also mark one value as the default.
There are two settings to know about when you create the field:
- Restrict picklist to the values defined in the value set. When this is on, the API rejects any value that is not in the list. When it is off, an integration or data load can insert new values, which then appear in the data but not in the list.
- Display values alphabetically. This changes only the order shown to users. It does not change the stored data.
Restriction is enforced for custom picklists you create with this setting. Treat it as the safer default, because unrestricted fields tend to collect stray values from imports.
Values and existing records
Deactivating a value hides it from new selections. Records that already hold the value keep it. Deleting a value gives you a choice. You can replace it on existing records with another value, or you can leave the records with an empty value.
Renaming a value in the setup screen can also update the stored data. Salesforce offers to update existing records when you edit a value. Rename deliberately, because reports and filters that use the old value should be reviewed afterward.
Multi-select picklists
A multi-select picklist is convenient but costly. Values are stored in one text field separated by semicolons. For example, a contact's Interests__c could hold Golf;Tennis;Chess.
This design causes several limits:
- Reports cannot group cleanly on each individual value.
- The field cannot be a controlling field for a dependent picklist.
- Each field supports a limited number of selected values, and the total length of the stored selection is capped.
- Formulas need
INCLUDES, and a simple equals comparison does not work. - Automation often needs string handling to split the value.
SOQL filters multi-select picklists with INCLUDES and EXCLUDES. A semicolon inside one string means that both values must be selected. Separate strings mean that either option matches.
SELECT Id, Name FROM Contact WHERE Interests__c INCLUDES ('Golf;Tennis', 'Chess')This query returns contacts who selected both Golf and Tennis, and contacts who selected Chess. It also returns contacts who selected all three.
In Apex, you read the field as a string and split it:
Contact c = [SELECT Interests__c FROM Contact LIMIT 1];
if (c.Interests__c != null) {
List<String> interests = c.Interests__c.split(';');
System.debug(interests);
}Picklists in formulas
A picklist value cannot be compared with a plain equals sign in a formula. Use ISPICKVAL, which takes the field and a text literal.
IF(ISPICKVAL(StageName, "Closed Won"), Amount, 0)This formula uses a Currency return type on Opportunity. It returns the amount only for won deals. Other picklist functions include TEXT(), which converts the selected value to text so that you can concatenate it or use CASE. For multi-select fields, use INCLUDES(Interests__c, "Golf").
Dependent picklists
A dependent picklist limits its values based on the value in a controlling field. The controlling field can be a standard or custom picklist or a checkbox. It cannot be a multi-select picklist. For example, a Country__c picklist could control a State__c picklist.
Keep these points in mind:
- The dependency is a matrix. Admins mark which dependent values are available for each controlling value.
- The dependency restricts the user interface. API behavior depends on the restriction setting, so verify it in your own org before relying on it for data integrity.
- A field can be both a dependent and a controlling field, which allows chains. Long chains become hard to maintain.
Global value sets
A global value set is a shared list of values that several picklist fields can use. You create it once in Setup and attach it to fields on any object. If you change the set, every field that uses it changes.
Use one when the same list must stay identical across fields. Examples are regions, product families and priority levels. Do not use one when the lists are likely to diverge. Fields that use a global value set cannot be edited to have their own values. You would need to change the set, or replace the field.
Standard value sets exist as well. They back fields such as Lead Status and Opportunity Stage, and you manage them in Setup.
Picklist, multi-select or checkbox
The choice depends on how many answers a record can hold and what you plan to do with them.
- If the answer is only true or false, use a checkbox. It is simpler and works in every formula and filter.
- If there is one answer from a list, use a picklist.
- If a record may have several answers and you only need to display or filter them, a multi-select picklist can work.
- If you need to report on, count or relate each answer, model them as records. Use a junction object, covered in a later chapter.
Common errors
- Using
=in a formula. The formula fails to save. Wrap the field inISPICKVAL. - Expecting a new value to appear after a data load. If the field is restricted, the load rejects rows with unknown values. Add the value to the list first.
- Misspelling a value in code. Apex compares picklist values as strings, so
'Closed won'does not match'Closed Won'in a case-sensitive comparison. Check the exact API value. - Treating a multi-select value as a single value. Use
INCLUDESin SOQL andsplit(';')in Apex. - Reusing one list by copying it. Copies drift apart. Use a global value set.
Exercise
A Contact needs a field that records every language the person speaks. Sales managers only need to filter contacts by language in list views, and no one needs to count speakers per language. Which field type fits, and how would a SOQL query find contacts who speak both French and German?
Show answer
A multi-select picklist fits, because the data is several values from a fixed list and the need is filtering. The query is SELECT Id FROM Contact WHERE Languages__c INCLUDES ('French;German'). The semicolon inside one string means both values must be selected. If managers later need counts per language, change the design to a junction object.
Exercise
Three objects each have a Region picklist with the same eight values. Admins keep updating one list and forgetting the others. What feature solves this, and what limit comes with it?
Show answer
A global value set solves it. All three fields share one list, so a change applies everywhere. The limit is that fields using the set cannot keep their own separate values, so use it only when the lists should stay identical.