How to Use CONTAINS Function in a Formula Field Salesforce?
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.
Follow Us