Posted in Salesforce Admin

Salesforce: Formula with CONTAINS() function TIPS

images (5)

Salesforce: Formula with CONTAINS() function

The CONTAINS function is mostly used in validation and workflow rules to search for a character or string in a text field.

BEHAVIOR#

CONTAINS(Text, compare_text)

  • CONTAINS will return TRUE if “compare_text” is found in “text” and FALSE if not.
  • The comparison is case sensitive.
  • When using CONTAINS function in a validation rule, fields that are blank are considered as valid in Salesforce. Like if you have a validation rule that tests to see if the serial number of an asset contains “A,” all assets that have a blank serial number are considered valid.

images (6)

  • USE CASES for this function
    1.Searching for Text
    Example 1: Like we have a custom field Comments__c on Contact and we don’t want user to enter Bad Word into Comments section . So here we can use this validation rule for prevent user to enter Bad data.

CONTAINS(Comments__c,”BadWord”)

  • Returns TRUE if “BadWord” is found anywhere in Comments__c.

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

Example 2: Like we

CONTAINS(“INDIA:JAPAN:US:UK”,Country)

Will return TRUE if Country is INDIA,JAPAN,US,UK or any exact match of “INDIA,JAPAN,US,UK”.

  • Before some days ago some user asked question on Success Community for Contains validation rule. User wants to save her records only when his custom field contain some specific word . Like we have one custom field My_Field__c and we want that user is able to save this only it will contain “Salesforce” otherwise it will prevent user’s from saving the record.

Formula:

IF((CONTAINS( My_Field__c,”Salesforce”)), false, true)

So it will verify here that T My_Field__c field having this Salesforce word then only it will save the record.

Reference:

images (3)

Advertisements

Author:

Hi! I am Pritam Shekhawat, Salesforce MVP. I am working as a 3x Certified Salesforce developer as well I am a co-leader of Noida Salesforce user group. Most important thing which I like about Salesforce is giving back. There aren’t enough words in the dictionary to describe the significance of giving back.

2 thoughts on “Salesforce: Formula with CONTAINS() function TIPS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s