CONTAINS() Function in Salesforce | Syntax, Examples, & Use Cases : Bijay Kumar
by: Bijay Kumar
blow post content copied from SalesForce FAQs
click here to view original post
### Summary of the Salesforce CONTAINS() Function The content discusses the **CONTAINS() function in Salesforce**, which allows users to check if a specific substring exists within a text field. This function is particularly useful in customer relationship management (CRM) scenarios, enabling businesses to categorize and analyze text data efficiently. #### Key Details: - **Function Purpose**: The CONTAINS function checks for the presence of a substring within a text field. - **Case-Sensitivity**: It differentiates between uppercase and lowercase letters. - **Usage**: The function can be employed in validation rules, workflow rules, or formula fields, but it requires the text field type parameter. - **Return Value**: It returns a Boolean value (True or False) based on whether the substring exists. #### Syntax: ```plaintext CONTAINS(text_field, substring) ``` - `text_field`: The text field in which you want to search. - `substring`: The substring you want to find. #### Example Use Case: The tutorial illustrates how to use the CONTAINS function to categorize leads based on keywords. For instance: ```plaintext IF( CONTAINS(Description, "refund"), "Refund Case", ... ) ``` #### Steps to Implement in Salesforce Lightning: 1. Access Salesforce Lightning and navigate to Setup. 2. Use the Object Manager to select the object (e.g., Lead). 3. Create a new field of type "Formula." 4. Enter the CONTAINS formula in the advanced formula editor. 5. Check for errors and set field-level security to make it visible to users. #### Conclusion: The CONTAINS function enhances data handling capabilities within Salesforce by allowing users to filter and categorize information based on specific keywords, improving CRM processes. ### Additional Information: Understanding how to implement the CONTAINS function can streamline operations in Salesforce, making it easier to manage customer interactions and data effectively. ### Hashtags for SEO: #Salesforce #CONTAINSFunction #CRM #SalesforceTutorial #DataManagement #SalesforceLightning #BusinessAnalysis #TextFunctions #LeadManagement #SalesforceFormulas #CustomerRelationshipManagement
While working at a company that uses Salesforce for customer relationship management, I needed to check whether a text field contained a specific substring.
As a solution, I found that Salesforce provides a function called CONTAINS that checks whether a specific text value exists within another text field.
In this tutorial, we will learn how to use the CONTAINS() function in Salesforce. We will also learn real-world business examples using the CONTAINS function syntax.
If you want to learn how to use the CONTAINS function in the formula field in Salesforce, let’s dive deep into the complete article and learn.
What is the CONTAINS() Function in Salesforce?
The Salesforce CONTAINS() function is one of the Text() Functions used to perform text operations. The CONTAINS function checks whether the text field contains the specified substring.
In addition to this, the CONTAINS function is case-sensitive, which means it knows the difference between uppercase and lowercase characters. And we can use this function in validation and workflow rules.
Moreover, you have to keep one thing in mind while working with this function: the passed text field must be of the TEXT field type. If you pass any other field type as a parameter to the function, you will get an error.
And if you are passing the simple text to the function as a parameter of the text field, make sure it is enclosed in single or double quotation marks.
Furthermore, this CONTAINS function returns a Boolean value (True or False) depending on whether the string passed matches the text field.
Syntax and Usage of the CONTAINS Function in Salesforce
Below is the syntax of the CONTAINS function in Salesforce:
CONTAINS(text_field,substring)
- text_field: This text_field parameter specifies the text field for which you want to check the presence of the substring.
- substring: This substring parameter specifies the substring that you want to find within the text field.
Here is an illustration of how to use a formula field’s “CONTAINS” function. Suppose we want to categorize leads’ cases based on keywords such as “Prospect”, “Inquiry”, or “Interested”.
Here is the formula:
IF(
CONTAINS(Description, "refund"),
"Refund Case",
IF(
CONTAINS(Description, "complaint"),
"Complaint Case",
IF(
CONTAINS(Description, "shipping"),
"Shipping Case",
"Other Case"
)
)
)
With this, we have learned the syntax of the CONTAINS function with an example. And now, we will proceed and learn how to use the CONTAINS function in Salesforce Lightning.
How to use the CONTAINS() Function in Salesforce
Below are the steps to use the CONTAINS function in Salesforce Lightning:
- Open Salesforce Lightning mode. Next, click the “Gear Icon” in the top right corner of the page. Click “Setup“ from the dropdown menu to continue.

- The setup page opens when you select the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.

- The object manager page opens when you click it. There are numerous objects seen here. Use the Quick Find search field to find the item on which we want to use the CONTAINS() function.
- Now, click the “Lead” object to move to the lead object page.

- 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.

- 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 TEXT function in the advanced formula.
- Click the “Next” button to move on to the next step.

- The choose output type screen appears after clicking the next button. Enter the information now by filling out the “Field Label” and the “Field Name”, which is automatically filled in when you put the cursor on the field name. In this instance, I typed “Lead Ranking” into the field label.
- Choose the “Output Data Type“ for the field in which we want to store the result. In this case, I check the radio button next to the “Number” data type to return the formula result as a number.
- Move to the next step by clicking the “Next” button.

- In the advanced formula editor, enter the CONTAINS() function formula. In this case, I use the CONTAINS() function to check the job title against the passed substring and assign a ranking to the lead. The formula is as given below:
IF(
CONTAINS(Job_Title__c, "Manager"),
8,
IF(
CONTAINS(Job_Title__c, "Engineer") ||
CONTAINS(Job_Title__c, "Developer"),
6,
IF(
CONTAINS(Job_Title__c, "Analyst"),
4,
2
)
)
)
- We use multiple IF statements to check whether the Job_Title__c field contains the specified substring using the CONTAINS function. If it contains, we assign Lead_Rating__c to the lead.
- Below are the cases that I have used in this example:
- The lead gets an 8 rating if the word “Manager” appears in the “Job_Title__c” field.
- The lead is awarded a rating of 6 if the job titles “Engineer” or “Developer” appear in the “Job_Title__c” field.
- The lead will receive a score of 4 if the word “Analyst” contains in the “Job_Title__c” field.
- The lead will be given a default score of 2 in all other conditions.
- Then, to ensure there is no error in the above-written formula, click on the “Check Syntax” button. You can define the “Description” and “Help Text” as well, and if you want, you can “Handle the empty field”.
- The above step is a purely optional step if you don’t want to fill up all such things, leave it and directly click on the “Next” button located at the top side of the page.

- 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.

- 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.

You can use the formula field once you have created it. Let’s look at an example:
- Create a new lead with the Job Title field open in the Lead Tab.
- Then save it, and move to the Details, here you will see the Lead Ranking field that displays the CONTAINS function result.
As a result, we have learned to use the CONTAINS function in Salesforce Lightning.
Conclusion
In a nutshell, we have learned the Salesforce CONTAINS function. In addition, we have learned about the CONTAINS() function in Salesforce syntax and its application in various real-world business scenarios.
You may like to read:
- CASESAFEID() Function in Salesforce
- BR() Function in Salesforce
- Salesforce Checkbox Formula
- Salesforce Formula Add Year to Date
- Salesforce Formula Add Months to Date
The post CONTAINS() Function in Salesforce | Syntax, Examples, & Use Cases appeared first on SalesForce FAQs.
November 26, 2025 at 12:18PM
Click here for more details...
=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Post a Comment