INCLUDES() Function in Salesforce

While working as a Salesforce Admin, our client wanted to track customer interest in buying a product using a multi-select picklist field called Interested Products on the Lead object.

The client wanted to check whether a lead selected Mobile from a list of options, such as Laptop, Mobile, and Accessories.

Based on this condition, the client wanted the lead automatically assigned to the Mobile Sales team. To meet this requirement, we used the INCLUDES() function to check whether the selected values include Mobile, even when multiple values are selected.

In this article, we will learn how to use the INCLUDES() Function in Salesforce. We will also learn the syntax and real-world examples, with step-by-step instructions for using the INCLUDES function in Salesforce.

What is the INCLUDES() Function in Salesforce?

Out of multiple TEXT functions in Salesforce, which are used to perform text operations on Salesforce fields, one is the Salesforce INCLUDES() function.

This Salesforce INCLUDES() function is used to check whether the value selected in a multi-select picklist field matches the specified text.

The syntax of the INCLUDES() Function in Salesforce is as given below:

INCLUDES(multiselect_picklist_field, text_literal)

Here is a detailed explanation of the parameters of the function:

  • multiselect_picklist_field: This multiselect_picklist_field parameter specifies the merge field name of the multi-select picklist, or you can say that it is the API name of the multi-select picklist field that you want to check.
  • text_literal: This text_literal parameter specifies the multi-select picklist value that you want to match in the quotes. Or, in simple words, you can say that it is the text value that you want to check with the multi-select picklist field value.

In addition, the Salesforce INCLUDES function returns a Boolean value (True or False). If the selected value in the multi-select picklist matches the passed text_literal, the function returns True. Otherwise, it returns False.

Moreover, there are some considerations that we must take care of while working with the Salesforce INCLUDES() function:

  1. Text Literal Text Type: In Salesforce, the INCLUDES Function, the text_literal parameter must be of the text type.
  2. Enclosed in Quotes: Make sure to always enclose the text_literal parameter in the quotes that show that it is of the text type.
  3. Text Literal Limitation: Always remember that the Salesforce INCLUDES Function’s text_literal parameter can’t be a merge field or the function’s resultant value.
  4. INCLUDES Function Errors: The Salesforce INCLUDES function gives you an error in the following cases:
    • No text_literal: If you have not provided a valid text_literal parameter or leave the parameter blank, you will get an error.
    • Empty text_literal: If you pass the text_literal parameter expression empty, such as “” or ” “, you will get an error.
  5. Determine Multi-Select Picklist Field Empty: If you want to check whether the multi-select picklist field is blank or not, you can use the Salesforce ISBLANK() Function.
  6. PRIORVALUE Function with INCLUDES Function: If you want to check the previous value of a multi-select picklist field that includes a specific value, you can use the PRIORVALUE function. It is useful when you want to track the changes in the multi-select picklist field value. Syntax: INCLUDES(PRIORVALUE(Mutli_select_picklist_field), text_literal)

Let’s see an example to understand better the concept of the INCLUDES() Function of Salesforce:

Suppose you are choosing people for jobs based on their skills. Let’s say you have a multi-select field that lets people select the skills they have, and, based on the specific job need, you create a formula that matches the selected field with the field you need for that job.

If the multi-selected field value matches the specific skill value, the “Required Skill” field becomes True. If not matched, the field becomes False.

Below is the formula for that scenario, and I use the INCLUDES function for that:

Here:

  • Multi-select picklist field name = Skills__c
  • Formula Field name = Required_Skill__c
IF(INCLUDES(Skills__c, "SQL"), True, False

Use the INCLUDES() Function in Salesforce

The following are the steps to use the Salesforce INCLUDES function in Salesforce Lightning:

  1. Click the “Gear Icon” in the top right corner of the page. Click Setup from the dropdown menu to continue.
INCLUDES Function in Salesforce
  1. The setup page opens when you select the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home Page. Click on it.
INCLUDES Function in Salesforce Example
  1. The object manager page opens when you click it. There are numerous objects seen here. Use the Quick Find search field to locate the item we want to use the INCLUDES() function on.
    • Here, I have selected the Lead object.
INCLUDES Function in Salesforce Lightning
  1. On the product object page, the “Field & Relationship” option is in the details section on the left. Select “Field & Relationship” from the menu.
    • The field and relationships page is opened after selecting the field and relationship option. Click the “New” button at the top of the page.
INCLUDES Function in Salesforce Lightning Example
  1. The field type page opens when you click the new button. The page contains a wide variety of field types. In this case, I chose the “Formula” field type, as I want to use the ISPICKVAL() function in the advanced formula.
    • Click the “Next” button to move on to the next step.
Salesforce INCLUDES Function
  1. Click Next to open the Choose Output Type step. Enter the Field Label and Field Name, then select the Formula Return Type.
    • In this example, enter Lead Categories as the field label and choose Text as the return type.
    • Click Next to continue.
Salesforce INCLUDES Function Example
  1. Click Next to open the Enter Formula step. Enter your formula and use the Advanced Formula tab to check for errors and access functions.
    • On the right side, open the Functions section and select Text from All Function Categories. Find the INCLUDES() function and click Insert Selected Function. The function will be added to the formula box. Replace the parameters with the required field and text value.

Example: If a lead selects multiple roles in a multi-select picklist, you can use the INCLUDES() function to check whether a specific role is selected and categorize the lead based on that role.

Below is the formula according to the above-defined example:

IF(INCLUDES( Lead_Roles__c , "Speaker"), "Speaker",
IF(INCLUDES( Lead_Roles__c , "Organizer"), "Organizer",
IF(INCLUDES( Lead_Roles__c , "Participant"), "Participant",
IF(INCLUDES( Lead_Roles__c , "Sponsor"), "Sponsor", "Other"))))

Here, we use the IF and INCLUDES functions in Salesforce to check the role of a lead based on the values selected in the Lead_Roles__c multi-select picklist field. The main goal is to categorize the lead roles.

Let’s understand the formula line by line:

  • The first IF checks whether the Lead_Roles__c multi-select picklist contains the value ‘Speaker’ using the INCLUDES() function. If true, it returns “Speaker”.
  • If the first condition is false, the second IF checks whether the field contains Organizer. If true, it returns “Organizer”.
  • If both conditions are false, the third IF checks whether the field contains Participant. If true, it returns “Participant”.
  • If all the above conditions are false, the last IF checks whether the field contains Sponsor. If true, it returns “Sponsor”.
  • If none of the conditions are met, the formula returns “Other”.
  1. Click Check Syntax to make sure the formula has no errors. If everything is correct, you will see the message “No syntax error in merge fields or functions.” If there is an error, Salesforce will show an error message.
    • You can also add a Description, Help Text, or choose how to handle empty fields if needed.
    • Click Next to continue.
INCLUDES() Function in Salesforce
  1. In this step, establish Field-Level Security. Choose the profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.
    • As I want it to be visible to all profiles, I have checked the “Visible” checkbox. After that, click the “Next” button located at the top.
Salesforce Lightning INCLUDES Function Example
  1. Add the custom field to the Page Layout after setting up the field-level security. Pick the page layout that has this field in it. If we do not select a layout, the field will not appear on any pages.
    • To save the formula field, click the “Save” button.
How to use the INCLUDES Function in Salesforce Lightning

Once the formula field is created, you can use this formula field. Let’s see an example:

  • Open the Leads item, create a new lead with the multi-select field “Lead Roles”, and save the leads.
  • After saving it, move to the Detail Section where you will get the “Lead Categories” field with the output of the INCLUDES function.

Let’s understand it with the example:

Suppose you have selected the “Participant” and “Sponsor” in the “Lead Roles” multi-select picklist field. The formula starts executing, matches the value chosen one by one against the passed text_literal value, and returns the result accordingly.

It checks the condition for both “Participant” and “Sponsor,” and both conditions become true independently. But no condition matches the specified conditions, i.e., for both “Participant” and “Sponsor”. Therefore, at the end of the formula, we return the default value “Other”.

As a result, we have learned how to use the INCLUDES function in Salesforce.

Conclusion

In conclusion, we have learned the syntax and several real-world business examples of the Salesforce INCLUDES function.

Additionally, we now know that to determine if any value selected in a multi-select picklist field equals a text literal, we need to use the Salesforce INCLUDE function. Furthermore, we have learned how to use the Salesforce INCLUDES function.

You may like to read the following articles:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.