2

I have a checkbox formula that evaluates true if:

Contains(Text_field__c, Account__r.lookup__r.Name)

If i have "test account" in the account__r.lookup__r.Name, and "test account" in the text_field__c it works. However, if I leave it blank, or type in a random word for text_field__c that does not match account__r.lookup__r.Name and vice versa, it still marks it true.

Shouldn't contains only work if "account__r.lookup__r.Name" is contained in text_field__c?

1

Refer CONTAINS function use cases and examples article.

Usage

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

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"

For your question, If i have "test account" in the account__r.lookup__r.Name, and "test account" in the text_field__c it works. However, if I leave it blank, or type in a random word for text_field__c that does not match account__r.lookup__r.Name and vice versa, it still marks it true.

The second example is working.

Update based on comments

Use REGEX instead of CONTAINS

REGEX(text, regex_text)

The Salesforce regular expression engine matches an entire string as opposed to searching for a match within a string. For example, if you are searching for the name Marc Benioff, use the regular expression, .*Marc Benioff.*, to find a match in a string like the following:

According to Marc Benioff, the social enterprise increases customer success.

If you use the regular expression, Marc Benioff, the only string that this regular expression will match is:

Marc Benioff
1

I found a work-around to this. I just carried over the lookup__r.name into a formula field onto the object with text_field__c. then I used contain there to evaluate it.

0

Try adding Not Null condition on Formula field

IF(AND(NOT( ISNULL(Text_field__c)  ), CONTAINS( TRIM(Text_field__c),TRIM(Account__r.lookup__r.Name) , )) ,true,false)
  • that still does not work, it marks it true if it is blank and contains text still that don't match – J.koh May 2 '18 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.