Count Selected Values in a Multi-select Picklist

Count Selected Values in a Multi-select Picklist

Last Updated on April 26, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

  • How to count the number of selections in a multi-select picklist?


After reading this blog, you’ll be able to:

  • Count the number of selections in a multi-select picklist 
  • understand how the PICKLISTCOUNT formula works
  • and much more 

Business Use case

Anita Smith is working as a Salesforce Consultant at Gurukul On Cloud (GoC). She has received a requirement from her Sales director to allow users to select only three options in the Preferred Destination multi-select picklist on Lead. 

Guided Practice (We-do): 

If you ever worked with a multi-select picklist, you know the pain when it comes to writing any logic using it. One of the common ask is how do I count the number of selected values when working with a multi-select picklist.

Now you can use PICKLISTCOUNT() formula to count selected values for the multi-select picklist. 

Formula Description
PICKLISTCOUNT(multiselect_picklist_field) It Returns the number of selected values in a multi-select picklist.

There are 2 steps to solve Anita’s business requirement using the Validation Rule. We must:

  1. Create a custom multi-select picklist on lead to track preferred destinations for vacation 
  2. Write a validation to display the error message, if more than three values have been selected for the destination 

Step 1: Create a Custom Picklist(Multi-Select) Picklist on Lead

First of all, we will create a multi-select picklist field on lead to track preferred destinations for a vacation. 

  1. Click Setup. 
  2. In the Object Manager, type Lead and select Lead
  3. Select Field & Relationship, then click New.
  4. Select Picklist (Multi-Select) as Data Type, then clicks Next.
  5. Choose output Type
    1. Enter Field Label and click the tab key, the API Name will populate. 
    2. Select Enter values, with each value separated by a new line for Values.
    3. Copy the countries’ values from GitHub and paste them into the box.
    4. # Visible Lines 4.
    5. Click on the Next button.
  6. Set the Field-level Security for the profiles, make sure to set this field as read-write. 
  7. Add this field to Page Layout.
  8. Click Save. 

Step 2: Creating a Validation Rule

  1. Click Setup.
  2. In the User Interface, clicks on Object Manager
  3. Navigate to Lead | Validation Rules and click on the New button.
  4. Enter a name in the Rule Name
  5. Active: True
  6. Error Condition Formula 
    1. PICKLISTCOUNT( rakeshistomMVP__Preferred_Destination__c ) >3
  7. Error Message
    1. Error Message: You can only select a maximum of 3 countries.
    2. Error Location: Preferred Destination
  8. Click Save.

Proof of Concept

Next time, when a Sales rep creates or updates a lead with more than three values in Preferred Destination – it will display an error message defined in the Validation Rule.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.