INCLUDES() Function in Salesforce

In this Salesforce tutorial, we will learn how to use the INCLUDES() Function in Salesforce. We will also learn the syntax and real-world examples with the step-by-step implementation of how to use the INCLUDES function in Salesforce Lightning and Salesforce Classic.

While working in the company as a Salesforce Developer, I got a task to categorize the problems faced by the customers based on the services provided by the company.

As a solution, I found that Salesforce has a function named “INCLUDES” using which I can categorize the problems and assign the relevant service provided.

If you completely want to learn how the INCLUDES function works in Salesforce, go through the complete article and learn with multiple examples.

What is INCLUDES() Function in Salesforce

Out of multiple TEXT functions in Salesforce which are used to perform the text operations on Salesforce fields one is Salesforce INCLUDES() function. This Salesforce INCLUDES() function is used when we need to check whether the value selected in a multi-selected picklist field equals the specified text or not.

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 i.e. True or False. If the selected value of the multi-select picklist matches with the passed text_literal, the function returns the result in True. Otherwise, it will return the result as 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 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 shows that it is of the text type.
  3. Text Literal Limitation: Always remember that the Salesforce INCLUDES Function text_literal parameter can’t be a merge field or the resultant value of the function.
  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 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 better the concept of the INCLUDES() Function of Salesforce:

Suppose you are choosing the persons for the jobs according to their skills. Let’s think you have a multi-select field that allows the persons to choose the skills that they have and according to the specific need of the job you create a formula that matches the selected field with the specific field that you need for the particular job.

If the multi-selected field value matches the specific skill value the “Required Skill” field becomes True. If not match, 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)

With this, we have learned about the Salesforce INCLUDES Function with the syntax, important considerations, and an example. Now, we will proceed and learn to use the INCLUDES Function of Salesforce in both Salesforce Lightning and Salesforce Classic.

Read ISPICKVAL() Function in Salesforce

How to use the INCLUDES() Function in Salesforce Lightning

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

Step 1: Open your Salesforce account in the Lightning Experience. If your account is not open on the main home page of Lightning setup. Click on the “Gear” icon at the top of the page, then from the dropdown click on the “Setup” option.

INCLUDES Function in Salesforce

Step 2: Once you reached the main home page of Lightning Experience, click on the “Object Manager” option in the navigation bar.

INCLUDES Function in Salesforce Example

On the click on the object manager, you will get the list of all the objects i.e. standard and custom. Now, look for the object in which you want to use the Salesforce INCLUDES function in the “Quick Find” search box and click on it.

Let’s take an example of the “Lead” object as I want to divide leads based on the different roles they can perform.

INCLUDES Function in Salesforce Lightning

Step 3: Once you click on the lead, you will be directed to the lead page where you will get all the functionalities-based options of the lead object. Click on the “Field & Relationship” option that you will get on the left side and after that click on the “New” button to create the new custom field where you can use the INCLUDES function.

INCLUDES Function in Salesforce Lightning Example

Step 4: After you click on the new button, you will be redirected to the step “Choose the Field Type”. Now, specify the type of information that the custom field will contain by choosing the “Data Type” accordingly.

See also  MFLOOR() Function in Salesforce

As we are going to use the INCLUDES function, so select the “Formula” field type by checking the radio button next to it. Then, click on the “Next” button to move to the next step.

Salesforce INCLUDES Function

Step 5: Once you will click on the next button, you will be redirected to the step “Choose Output Type”. In this step, first, you need to enter the “Field Label” and “Field Name”, after that choose the “Formula Return Type”.

In this example, I entered the field label as “Lead Categories” and when I click on the field name box it automatically fills up. After that, I choose the “Text” as the formula return type field by checking up the radio button next to the text as I want to get the result in the text format.

Then, click on the “Next” button and move to the proceeding step.

Salesforce INCLUDES Function Example

Step 6: After you clicked on the next, you will be moved to the next step which is “Enter Formula”. Here, you have to enter your formula and check the syntax for errors by clicking on the advance formula subtab to use the additional fields, operators, and functions.

For this, first, you need to move to the right side of the page, where you will get the “Functions” sections and here click on the dropdown menu labeled “All Function Categories”.

Once you click you will get the dropdown with various function categories, choose “Text” from them as you know that the INCLUDES function is part of the text function category in Salesforce. After you click on the text, you will get the list of all the text functions now scroll down, search for the “INCLUDES” function, and click on it once you find it.

Once you click on the function, you will get the button “Insert Selected Function” under the functions section box. Now, the function is inserted into the advance formula box, replace the parameters of the functions with field, text, etc.

Let’s see an example: Suppose you got a task to differentiate the lead based on various roles they are performing. And you have a multi-select field that allows the lead to choose the roles they can perform and according to your requirement, you create a formula that matches the role selected with the value you have passed in the text_literal and differentiate the lead according to that in different categories.

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 of Salesforce that check the role of a lead based on the values selected in the “Lead_Roles__c” multi-select picklist field. As your, main agenda is to categorize the lead roles.

Let’s understand the formula line by line:

  • The first IF checks if the “Lead_Roles__c” multi-select picklist field has the value “Speaker” using the INCLUDES function. If the condition becomes true, it returns the result “Speaker”.
  • The second IF works when the first condition failed and here we use the INCLUDES function that checks if the multi-select picklist field “Lead_Roles__c” includes the value “Organizer”. If the condition is true, it returns the result as “Organizer”.
  • The third IF function works only if the first and second condition becomes false. Here, we check if the multi-select picklist field “Lead_Roles__c” has the value “Participant” using the INCLUDES function. If the condition is passed, it returns the result as “Participant”.
  • The last IF function works when the first three conditions failed. Here, we use the INCLUDES function that checks if the multi-select picklist field “Lead_Roles__c” includes the value “Sponsor”. If the condition is true, it returns the result as “Sponsor”.
  • If all four conditions get failed, it returns the category as “Other”.

Step 7: Click on the check syntax button to verify that there is no error in the above-defined formula. If the formula is error free you will get the message “No syntax error in merge fields or function”. However, if there is an error, you will get an error message.

Optionally, if you would like you can add the “Description”, “Help Text”, as well as “Handle the empty fields”. After that, click on the “Next” button to move toward the next step.

Salesforce Lightning INCLUDES Function

Step 8: In this step, you need to establish field-level security. Here, you have to choose the profile to whom you want to grant the field-level security edit access to the above-created custom formula field.

In this example, I check the checkbox next to the “Visible” option and after that, click on the “Next” button to move to the next step.

Salesforce Lightning INCLUDES Function Example

Step 9: In this, you are redirected to the “Add to page layouts” step. Select the page layout that should include this field. And note one thing, this field will be added as the last field in the column section of this page layout. If you don’t select a layout, the field will not appear on any pages.

See also  Salesforce ADDMONTHS Function

At last, click on the “Save” button to save this above-created custom formula field with the INCLUDES function.

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 and matches the selected value one by one with the passed text_literal value and returns the result according to it.

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

With this, we have learned how to use the INCLUDES function in Salesforce Lightning. Now, we will move ahead and learn how to use the INCLUDES function in the Salesforce Classic.

Read LEFT Function in Salesforce

How to use the INCLUDES() Function in Salesforce Classic

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

Step 1: Open your Salesforce account in the Salesforce Classic Experience. If by default your account gets opened in the Lightning Experience, click on “Profile” and then click on the option “Switch to Salesforce Classic” from the dropdown.

INCLUDES Function in Salesforce Classic

Step 2: Once you successfully, logged into the Salesforce Classic click on the “Setup” option at the top between your name and help option.

INCLUDES Function in Salesforce Classic Example

Step 3: After you clicked on the setup, you will be directed to the main setup page of the classic experience. Scroll down to the “Build” section at the left side of the page and from here click on the “Customize” dropdown.

Now you will get the list of all the Salesforce Classic objects both standard and custom. Choose the Salesforce object on which you want to use the Salesforce INCLUDES function.

Let’s take an example of the “Accounts” object as I want to categorize the accounts based on the different cities. Click on the “Accounts” dropdown, and click on the “Fields” from the options.

Salesforce Classic INCLUDES Function

Step 4: Once you click on the fields, the accounts page having all the custom and standard fields get opened. Scroll down to “Accounts Custom Fields & Relationships” and click on the “New” button to create a new custom field.

Salesforce Classic INCLUDES Function Example

Step 5: In this “Choose the Field Type” step, you have to specify the type of information that the custom field will contain by choosing the “Data Type”.

As your main objective is to use the INCLUDES function, select the “Formula” field type by checking the radio button next to it. After that click on the “Next” button and move to the next step.

How to use the INCLUDES Function in Salesforce Classic

Step 6: As you click on the next button, you will be on the “Choose Outype Type” step. Here, you need to enter the “Field Label” and “Field Name” and then you also need to choose the “Formula Return Type”.

In this example: I entered the field label as “Account Zones” and when I clicked on the field name box it gets automatically fills up. Then, I scroll down and choose “Text” as the formula return type by checking the radio button next to the text. After that click on the “Next” button to move to the next step.

Use the INCLUDES Function in Salesforce Classic

Step 7: In this step, you have to enter the formula and check the syntax for errors by clicking on the advance formula subtab to use the additional fields and functions.

Move to the right side of the page towards the “Functions” sections and from this click on the dropdown named “All Function Categories”. Now, from here choose “Text” as you know that the INCLUDES function is one of the text functions.

Once you click on the text it shows you all the functions under the text category, search for the “INCLUDES” function and click on it. Click on the “Insert Selected Function” button that will appear under the functions section box once you have clicked on the function. The function has now been added to the advance formula box and now replaced the parameters of the function with text, fields, etc.

Example: Suppose you are working in a company where you got a task to track the different accounts’ locations, and each account can have access to choose multiple cities where they are located. Now your task is to categorize these accounts into different zones based on the cities where they have their accounts.

To solve your task, you need to create a formula that checks the cities an account has selected and assigns them to the appropriate zone based on the cities they have selected. Basically, the formula checks each city one by one, and if it finds the match, assigns the account to the respective zone.

See also  ASCII() Function in Salesforce

To do this process, you can use the Salesforce INCLUDES functions which check the cities selected by the account. Once the match is found the formula stops checking and assigns the account to the appropriate zone.

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

IF(INCLUDES(Account_Located_Cities__c, "New York") || INCLUDES(Account_Located_Cities__c, "Boston") || INCLUDES(Account_Located_Cities__c, "Philadelphia"), "East Zone",
IF(INCLUDES(Account_Located_Cities__c, "Los Angeles") || INCLUDES(Account_Located_Cities__c, "San Francisco"), "West Zone",
IF(INCLUDES(Account_Located_Cities__c, "Chicago") || INCLUDES(Account_Located_Cities__c, "Dallas") || INCLUDES(Account_Located_Cities__c, "Minneapolis"), "Central Zone",
IF(INCLUDES(Account_Located_Cities__c, "Miami") || INCLUDES(Account_Located_Cities__c, "Atlanta"), "South Zone",
"Other"))))

Here, we use the IF, INCLUDES, and OR functions of Salesforce that categorize accounts into different zones based on the cities selected in the “Account_Located_Cities__c” multi-select picklist field.

Let’s understand the formula line by line:

  • The first IF function checks if the “Account_Located_Cities__c” multi-select picklist field has the values “New York”, “Boston”, or “Philadelphia” using the INCLUDES and OR functions. If the conditions become True, the formula returns “East Zone”.
  • The second IF function works when the first condition failed and here we use the INCLUDES and OR functions that check if the multi-select picklist field “Account_Located_Cities__c” includes the values “Los Angeles” or “San Francisco”. If the condition is True, the formula returns “West Zone”.
  • The third IF function works only if the first and second conditions become failed. Here, we check if the multi-select picklist field “Account_Located_Cities__c” has the values “Chicago”, “Dallas”, or “Minneapolis” using the INCLUDES and OR function. If the condition is True, it returns the result as “Central Zone”.
  • The last IF function works when the first three conditions failed. Here, we use the INCLUDES and OR functions that check if the multi-select picklist field “Account_Located_Cities__c” includes the values “Miami” or “Atlanta”. If the condition is True, the formula returns “South Zone”.
  • If all the conditions get failed and none of the specified cities match with any of the zones, the formula defaults to returning “Other”.

Step 8: After entering the formula in the advanced formula subtab, click on the “Check Syntax” button to verify whether the above-written formula is correct or not. If there is no error in the formula, you will get the message “No Syntax errors in merge fields or function”. Otherwise, you will get an error message.

You can also, at your own choice, define the “Description”, “Help Text”, and “Handle the empty field” before selecting the “Next” button to proceed to the next step.

How to use the INCLUDES Function in Salesforce Classic Example

Step 9: After you click on the next button, you will be directed to the “Establish Field-Level Security” page. In order to customize field-level security, you must here select the profiles to whom you want to provide editing access to the field. This specific field will be hidden from all the profiles if you haven’t selected a profile.

In this example, I have selected the “Visible” checkbox because I want every person on the profiles to have the ability to change this field information. Then, to go to the next step, click the “Next” button.

How to use the INCLUDES Function in Salesforce

Step 10: In this “Add to Page Layout” step, you must select the page layout in which the newly created custom formula field will be included. After that, click on the “Save” button to save the formula field.

How to use the INCLUDES Function in Salesforce Example

You can use the formula field after you have created it. Let’s look at an example to show how it works:

  • Open the Accounts item, create a new account with the multi-select field “Account_Located_Cities__c” and save the accounts.
  • After saving it, move to the Detail Section where you will get the “Account Zones” field with the output of the INCLUDES function.

Let’s understand this with the example:

Suppose, you have selected “Chicago” and “Minneapolis” in the Account_Located_Cities__c multi-select picklist field. The formula starts executing and matches the selected value one by one with the passed text_literal value and returns the result according to it.

It checks the condition for both “Chicago” and “Minneapolis” and both conditions become true independently when it checks the central zone group. So, the formula returns “Central Zone” as the result because the selected cities match the cities in the central zone group of the formula.

Example of Salesforce INCLUDES function

With this, we have learned the steps of using the INCLUDES function in Salesforce Classic.

Conclusion

In conclusion, we have learned the syntax and several actual business-related examples for 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 you specify we need to use the Salesforce INCLUDE function.

Furthermore, we have learned how to use the Salesforce INCLUDES function in both Salesforce Lightning and Salesforce Classic.

You may like to read the following articles: