Loading

Use case and examples of the 'CONTAINS' function

Дата публикации: Sep 25, 2024
Описание

The CONTAINS function compares 2 text strings and is commonly used in validation and workflow rules to search for a character or string in a text field. For more information, please review CONTAINS and  Formula Operators and Functions by Context (right-click links and open link in a new tab).

Решение

CONTAINS usage

1. Search for text.
2. Check if an unknown string or character matches a defined set of strings or characters.

CONTAINS examples

Example of searching for text.

CONTAINS(Comments__c,"BadWord")
Returns TRUE if "BadWord" is found anywhere in Comments__c.


Example of searching for  unknown string or characters.

CONTAINS("0123456789", TextField__c)
Will return true for TextField__c values such as 1,2,9,01,789, or any other substring of "0123456789"

 
CONTAINS("0123456789", LEFT(TextField__c,1))
To only match numbers 0-9, the compare_text length must equal 1. In this case, the formula is checking to see if the first character of TextField__c is a number between 0-9.
 

When using CONTAINS to compare a string with a defined set the length of the elements of the set should match the length of the string being compared. However, it's still possible to match the delimiter. An equivalent CASE statement would be longer but more reliable.

Note: The CONTAINS function considers BLANK value as true. Include NOT(ISBLANK() along with CONTAINS to meet requirements. If using NOT on CONTAINS, it does not recognize BLANK values.

Дополнительные ресурсы

Examples of Advanced Formula Fields

Номер статьи базы знаний

000385300

 
Загрузка
Salesforce Help | Article