This Salesforce tutorial will explain about Salesforce PICKLISTCOUNT Function. We will also learn the syntax and use cases of the PICKLISTCOUNT Salesforce function. In addition, we will explore the practical business examples of the function in both Salesforce Lightning and Salesforce Classic.
While working as a Salesforce administrator in a company that uses Salesforce to manage customer data, sales, and support cases. I recently got the task of counting the number of opportunities in each stage of the sales pipeline for tracking sales performance.
To fulfill this requirement, I decided to create the formula field where I can use the PICKLISTCOUNT function and count the multi-select picklist selected values. So, if you want to demonstrate how to use the PICKLISTCOUNT in Salesforce, with examples in both Salesforce Lightning and Salesforce Classic, you are in the right article.
Let’s dive deep into the article and learn the concept of the PICKLISTCOUNT Salesforce Function.
What is Salesforce PICKLISTCOUNT Function
Salesforce PICKLISTCOUNT Function is one of the various TEXT functions in Salesforce which is used for performing text operations on Salesforce fields. This Salesforce PICKLISTCOUNT Function is used to return the number of selected values in a multi-select picklist.
As we all know, in a multi-select picklist we can choose multiple values from the list of defined options. So when there is any case where the developer needs to evaluate and determine selected values within this field and count selected items we will use the PICKLISTCOUNT function.
In addition, we can use this function in various cases in Salesforce such as reporting, workflow automation, formula fields, or validation rules. Furthermore, the syntax of the PICKLISTCOUNT function is simple and easy to grasp and given as below:
Here, the multiselect_picklist_field parameter specifies the name of the multi-select picklist field for which we want to count the selected values.
Moreover, we have to take care of one more thing the formula always results in a Number data type and is incompatible with other data types such as Time, Date, Text, Checkbox, etc.
If you pass any other data type rather than a multi-select picklist to the PICKLISTCOUNT function such as text, number, date, date/time, etc. you will get an error “Incorrect parameter type for function ‘PICKLISTCOUNT()’.”
Let’s see a small example of the PICKLISTCOUNT() function to better understand the concept:
Suppose you have a multi-select picklist field named “Electronic Gadgets You Have”. This picklist contains the following options Phones, Laptops, Cameras, Tablets, Headphones, iPads, Smart Watch, and Personal Computer.
Let’s think out of all the values, you have selected the following values “Phones”, “Laptops”, “Headphones”, and “Smart Watch” from this multi-select picklist.
So, if you use the PICKLISTCOUNT() function, it returns you the count of the selected values as 4 in your course, because you have chosen the four options from the multi-select picklist.
With this, we have learned what is the Salesforce PICKLISTCOUNT function, its syntax, and one example of the function to get a better understanding. Next, we will move ahead and learn how to use the PICKLISTCOUNT function in the formula field in both Salesforce Lightning and Classic with examples.
How to use PICKLISTCOUNT Function in Salesforce Lightning
The following are the steps to use the Salesforce PICKLISTCOUNT Function to determine the number of selected values in a multi-select picklist field.
Step-1: Login to the Salesforce account in Lightning experience. If you are not on the main home page setup, locate the “Gear” icon on the right-hand side of the page. Click on it and it shows the dropdown menu, from here select the “Setup” option and you will be redirected to the setup page for the current app.
Step-2: After successfully moving to the main home page setup in the Lightning Experience, click on the “Object Manager” option from the navigation bar.
Step-3: On clicking, the object manager page will open, with the list of all Salesforce custom and standard objects. Find the out-of-it object where you want to utilize the Salesforce PICKLISTCOUNT function.
In this example, I decided to apply the PICKLISTCOUNT function on the product object. So, I enter the Product into the “Quick Find” box and then click on the “Product” object when it appears in the search results.
Step-4: Once you click on the product you will be directed to the product page, where you can access all the functions related to the product. On the left side of the page, locate and select the “Field & Relationship” option. After that click on the “New” button as you need to create a new field where you use the PICKLISTCOUNT function in a formula field.
Step-5: In this step, you will get the various “Salesforce Field Types” and from here you select any one of the data types as per your specific needs. As per your requirement, you have to choose the formula field type, as you want to create a formula field utilizing the PICKLISTCOUNT function.
So, to select the formula field, simply click on the radio button next to the “Formula” field type. After that to proceed to the next step, click on the “Next” button.
Step-6: Now, enter the “Field Label” and, “Field Name” and choose “Formula Return Type”. In my case, I entered the field label as “Total Price” and on clicking, the field name is automatically populated.
After that scroll down to the page and select the formula return type from available field types. As you know the function returns results in numbers, so you need to choose a number kind of data type, but as you are calculating the price and you know that Salesforce also provides us with the currency data type which is also the number kind data type.
Therefore, in this case, you have to choose “Currency” as the formula return type, by clicking on the radio button next to the currency field type. In my case, I keep the “Decimal Place” value the same as by default if you want to change you can change it. Then, to move to the next step, click on the “Next” button.
Step-7: In this step, you need to enter the formula according to your requirements. For this, first, navigate to the right side of the page, where you see the “Functions” section from here click on the dropdown labeled “All Functions Categories”.
From this dropdown, select the “Text” category because you know that the PICKLISTCOUNT function falls under the text category of Salesforce functions. On selecting the text, you will get the list of Salesforce functions that are categorized under text functions.
Now, search for the “PICKLISTCOUNT” function, select it, and click on the “Insert Selected Function” button. After the function is inserted into the advanced formula box, you can add parameters according to your specific requirements.
Let’s imagine an example: Suppose you are working in a customizing gifts company where customers can customize their gift by selecting multiple options like color, size, and material. On the basis of the customization total product price is calculated.
For selecting the customizations you have various multi-select picklist fields, so to calculate the total amount on the number of customizations selected, you decided to use the PICKLISTCOUNT function.
According to the scenario, the formula is as given below:
Basic_Charges__c + (PICKLISTCOUNT(Color__c) * 50) + (PICKLISTCOUNT(Size__c) * 100) + (PICKLISTCOUNT(Material__c) * 300)
Here, is a detailed explanation of the formula:
- First, define the basic cost or service charge of the product.
- Then, use the PICKLISTCOUNT function that counts the number of colors selected by the customer. After that, we multiply it by the additional cost of 50 based on the color selected.
- Next, use the PICKLISTCOUNT function that calculates the additional cost based on the number of sizes selected by the customer, and per size we multiply the size by 100.
- After that, use the PICKLISTCOUNT function that calculates the additional cost based on the number of selected materials to be used in customizing the product, and as per each material take an additional amount of 300.
- Last, we use the + operator to add all the results of the parts and get the total price accordingly.
Step-8: After entering the formula in the subtab, click on the “Check Syntax” button to ensure that the formula is error-free. If there are no errors, you will receive a message like “No syntax errors in merge fields or function”. But if there are any errors, an error message appears showing you the issue.
Even, you can enter information in the “Description” and “Help Text” fields, and configure how the field should handle empty values. After that, click on the “Next” button and move to the next step.
Step-9: In this step, you have to set up the “Field Level Security”. Here, you will need to select the profiles for which you want to grant edit access to this field. In this case, I have checked the checkbox next to the “Visible” option as I want to grant access to all.
Then, click on the “Next” button to move to the next step.
Step-10: This step adds this custom field to the page layout. Select the page layout names where you wish to include this field. By default all page layouts are selected, if you want to don’t include this custom field on any specific page layout uncheck it.
Otherwise, click on the “Save” button to complete the process of creating a formula field in Salesforce where you can use the PICKLISTCOUNT function.
Step-11: Once the formula field is created, you can use the formula field. Let’s see an example:
- Open the “Products” item, create a new product with the “Basic Charges”, “Color”, “Size”, and “Material” and save the product.
- Once you save, move to the product details page. Here you will observe the “Total Price” field that shows you the result of the PICKLISTCOUNT function.
Let’s deeply understand it with the example:
Suppose you have created the product with the basic charge of “$200”, the color selected as “Red”, “Grey”, the size selected as “7.5” x 11.5″”, and the material selected as “Leather” and save it. Then the formula executes and gives the total price as “$700”. Hence the formula effectively counts the multi-select picklist selected values and calculates the total price.
- Basic Charges: $200
- Color: PICKLISTCOUNT(Color__c) * 50: As two color are selected the PICKLISTCOUNT function returns the result as 2 and then multiply it by 50 and give the final result as 100.
- Size: PICKLISTCOUNT(Size__c) * 100: As only one size is selected the PICKLISTCOUNT function returns the result as 1 and then multiplies it by 100 and gives the final result as 100.
- Material: PICKLISTCOUNT(Material__c) * 300: As only one material is selected the PICKLISTCOUNT function returns the result as 1 and then multiplies it by 300 and gives the final result as 300.
- Total Price: Basic Charges + Color + Size+ Material = 200 +100+ 100+ 300 = $700
With this, we have learned the use of the PICKLISTCOUNT function in Salesforce Lightning. Now, we will move and explore the implementation of the PICKLISTCOUNT function in Salesforce Classic, with the help of an example.
How to use PICKLISTCOUNT Function in Salesforce Classic
The following are the steps to use the Salesforce PICKLISTCOUNT Function to count Selected Values in the Picklist Multi-Select field in Salesforce Classic:
Step-1: If your account opens in the Lightning Experience, and you want to move to the Salesforce Classic Experience, click on “Profile” and select “Switch to Salesforce Classic” from the dropdown menu.
Step-2: After logging in successfully to Salesforce Classic, locate the “Setup” option at the top, situated between your name and the help option, and click on it.
Step-3: Once you have clicked on the setup option and are redirected to the main setup page in the Salesforce Classic Experience, scroll down to the “Build” section on the left side of the page and locate and click on the “Customize” dropdown.
Now, you will see a list of all Salesforce Classic objects, including both standard and custom ones. Choose the specific Salesforce object where you utilize the PICKLISTCOUNT function. For example, let’s consider the “Leads” object for this example. Click on the leads dropdown, and then select “Fields” from the available options.
Step-4: In this step, you will directed to the lead page displaying all the custom and standard fields. Scroll down till you find the “Leads Custom Fields & Relationships” section, from here click on the “New” button to start the creation of a new custom formula field.
In the “Choose the Field Type” step, you need to specify the type of information that the custom field will contain. As your main goal is to utilize the PICKLISTCOUNT function, select the “Formula” field type by selecting the radio button next to it. Next, click on the “Next” button to proceed to the next step.
Step-5: After clicking on the next function, you will be on the “Choose Output Type” step. Here, you should enter the “Field Label” and the “Field Name”. In this example, I entered “Skill Count” as the field label and the field name may automatically populate when you click in the box.
Then scroll down and choose the “Number” as the formula return type by checking the radio button next to it. Then set the “Decimal Places” value to 2. After that, click on the “Next” button to move to the next step.
Step-6: Once you click the next, you will need to enter the formula in the advance formula sub-tab. To use the functions, move to the right side of the page, to the “Functions” section, and click on the dropdown labeled “All Function Categories”.
Now, select the “Text” category as you know the PICKLISTCOUNT function falls under the category of text functions. The list of functions will be displayed to you now, find the “PICKLISTCOUNT” function and click on it. After selecting the function, click on the “Insert Selected Function” button below the functions section.
After that replace the function’s parameters with the appropriate text, fields, or operators as needed. Let’s imagine the scenario that shows the usage of the Salesforce PICKLISTCOUNT function.
Suppose you got a task to track the number of skills each lead has in the organization. If you start counting it manually, it becomes a very complicated and time-consuming task. But then you say thank god as your organization is Salesforce based and this complicated task becomes easy for you.
To achieve this task, you decided to use the PICKLISTCOUNT function that counts the number of selected skills for each lead based on the multi-select picklist field that stores the record of skills. Below is the formula according to the above-defined scenario:
Here, we use the PICKLISTCOUNT function in Salesforce which is used to count the selected value in the picklist multi-select field. We use the custom field named Skills which counts the values selected in the picklist multi-select field skills. In simple words, the formula determines the skills selected by the leads from the list of available skill sets.
Step-7: After entering the formula in the advance formula subtab, click on the “Check Syntax” button to check whether the formula is correct or has any errors. If there is no error, you will get the message “No Syntax errors in merge fields or function”. But, if there are errors in the formula, you will receive an error message.
In addition, you have the option to enter a “Description” and “Help Text” for the formula so you know more about the formula in detail. Moreover, you can specify “How to handle the formula when the field is blank”. For this, choose either to treat blank fields as zeroes or as blanks, depending on your preference and the specific requirements of your formula.
Then, click on the “Next” button and move to the next step.
Step-8: After clicking on the next button, you will be moved to the “Establish Field-Level Security” step. Here. you can customize the field-level security by selecting which profile can have edit access to the field. If you don’t select any profiles, the field will be hidden from all profiles.
In this case, I have selected the “Visible” checkbox as I want all the users of the selected profiles can have access to modify the information related to this field in the future. To proceed to the next, click on the “Next” button and move.
Step-9: Last, you will be on the “Add to Page Layout” step. Here, select the page layout that should include this field. The field will be added as the last field in the first 2-column section of these page layouts. The field will not appear on any pages if you do not select a layout.
By default all page layouts are selected, if you want to don’t include this custom field on any specific page layout uncheck it. Then, click on the “Save” button to complete the process of creating a formula field in Salesforce where you can use the PICKLISTCOUNT function.
Step-10: Once the formula field is created, you can use the formula field. Let’s see an example:
- Open the “Lead” item, create a new lead with the “Skills” field, and save the lead.
- Once you save, move to the lead details page. Here you will find the “Skill Count” field that shows you the result of the PICKLISTCOUNT function.
Let’s deeply understand it with the example:
Suppose you have created a lead with the skills “Java”, “Python”, “SQL”, and “Communication” and save it. Then the formula executes and gives the skill count as 4. Hence the formula effectively counts the selected multi-select picklist values and calculates the skill count.
With this, we have learned the use of the PICKLISTCOUNT function in Salesforce Classic, to count selected values in the picklist multi-select field.
In a nutshell, we have learned the Salesforce PICKLISTCOUNT function that it is used to count selected values in the multi-select field in Salesforce. We have also learned the syntax and practical examples that show the implementation of the PICKLISTCOUNT function.
Moreover, we have explored the step-by-step implementation of how to count the selected values in the picklist multi-select field in Salesforce Lightning and Salesforce Classic with examples.
You may like to read the following articles:
- MID Function in Salesforce | How to get substring in Formula Field in Salesforce
- Salesforce REVERSE Function | How to reverse string in Salesforce
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.