FIND() Function in Salesforce | Syntax, Examples, & Use Cases

While working at a company that uses Salesforce CRM, I was tasked with reviewing customer reviews and, based on them, handling urgent case situations.

As a solution, I found the Salesforce FIND() function. So, if you want to know how to find the position of a search text string in the text or how to use the FIND function with real-life business examples, go through this complete article.

In this tutorial, we will learn how to find the position of a search string within a text field using the FIND() function in Salesforce.

What is the FIND() Function in Salesforce?

FIND() Function in Salesforce is one of the available TEXT() Functions in Salesforce, which is used to perform text operations on the fields. This FIND() Function returns the position of the search text string as a number.

In addition, the following is the syntax of the Salesforce FIND function:

FIND(search_text, text [, start_num])

Here is a detailed description of the parameters:

  • search_text: The search_text parameter specifies the string or substring that you want to find.
  • text: The text parameter specifies the field or expression in which you are searching for the substring.
  • start_num: The start_num parameter specifies the starting number for the search. And this search process always begins at the left side of the string and proceeds to the right.

Moreover, several considerations must be kept in mind when using the Salesforce FIND() function.

  1. Remove brackets[]: If you are working with the Salesforce Find Function, always remember to remove the square brackets [] before validation. If you have not done this, you will get an error.
  2. Starting Character: In Salesforce Find Function, the first character of the string is represented as zero rather than one.
  3. Blank text Parameter: The Salesforce formula field displays zero if you are using the Find Function and don’t pass any field or expression in your text parameter.
  4. Unique start_num Parameter: In some cases, the start_num parameter behaves differently. For example, if you use this Find Function in the field containing the website name, the start_num parameter behaves differently because the http:// is automatically added to the beginning.
  5. Case Sensitive: The search_text parameter is case-sensitive in nature, which means the Lower and Upper Case characters behave differently.
  6. Zero as Result: The zero is displayed as the result of the field where you use the Find Function function, and the start_num parameter value is greater than the length of the text.
  7. Wild Characters: If you are working with the Salesforce Find Function, note down one thing: the search_text parameter cannot contain any wildcard character.
  8. Negative start_num: The zero is displayed as the result of the formula field where you have used the Find Function if the start_num parameter is not greater than 0, i.e., a negative number.
  9. No Result Cases: If the Find Function does not return the search result, a zero is displayed in the field.
  10. Optional Parameter: In the Salesforce Find Function, the start_num parameter is optional. The function uses the first character of the string if you don’t pass any value to the start_num.

In addition, keep in mind that the provided text field parameter must be of the TEXT field type while using this function. You will encounter an error if you give the function any other field type as an argument.

Let’s look at a simple example of the FIND() function before proceeding to a better understanding of the topic.

Suppose you are working in the marketing team of a company that uses Salesforce as the tool, and you have to assign the lead to the marketing campaigns based on the description of the lead. And for this, you also have to use the FIND Function of Salesforce, so here is the formula:

IF(FIND('Google Ads', Lead_Description__c) > 0, 'Google Ads', IF(FIND('Twitter', Lead_Description__c) > 0, 'Twitter', 'Newspaper'))

With this, we have learned the basics of the FIND function, including its syntax and key considerations. We have also learned just a small example to understand it deeply.

Now, we will move on to the next topic and learn how to use the FIND() Function in Salesforce Lightning and Classic to find the position of the search text string within the text.

Use the FIND() Function in Salesforce

Here, you will learn how to use the FIND Function in Salesforce Lightning to find the position of the search text string in the text. Let’s take a look at a hypothetical situation to help you understand the idea.

Suppose you are working at a sales company and want to determine whether a product is a single unit or a combo using the FIND Function in Salesforce based on the product description.

So, for this, you search for terms like “combo“, “bundle”, and “package” in the product description, and then divide the product into two categories: “Combo Product” and “Single Product”.

The following are the steps to use the FIND Function for the above-defined scenario:

  1. First, log in to Salesforce mode and navigate to the right corner of the page. Then, click on the “Gear Icon”. Now, from the dropdown menu, click on Setup.
FIND Function in Salesforce
  1. From the left side of the menu, click on “Object Manager”.
FIND Function in Salesforce Example
  1. Now, search for the object in the “Quick Find Search” box on which you want to use the FIND function.
    • As I defined in the above scenario, I want to determine whether the product is a single unit or a combo. So, I searched for the “Product” object and clicked on it.
  1. From the left side of the page, click on the Field & Relationship option.
    • Click on the “New” button to create a new field where we can use the FIND() function.
FIND Function in Salesforce Lightning Example
  1. It will redirect to the “Choose the field type” page. Now, check the radio button in front of the “Formula” data type.
    • To proceed to the next step, click on the “Next” button.
FIND() Function in Salesforce
  1. Enter the “Field Label” for the formula, and the unique “Field Name” will be automatically populated. In this case, I entered the field label named “Product Combo type”.
    • Choose the Data Type for the field.
    • Move to the next step by clicking on the “Next” button.
Salesforce FIND Function Example
  1. Now, move to the right side of the formula editor box towards the “Function Section”, and from the dropdown choose the “Text Categories Functions“.
    • From the Text Categories Function, select the function FIND from the list of text functions and enter it into the formula editor.
    • In this example, I use the FIND function to determine whether the product is a single unit or a combo. The formula is as follows:
    IF(FIND('bundle', Product_Description__c) > 0 || FIND('combo', Product_Description__c) > 0, 'Combo Product', 'Single Product')
    
    • Here, we use an IF statement that checks the field “Product_Description__c” and attempts to find the position of the search string ‘bundle’ or ‘combo’ using the FIND() function in Salesforce.
    • If any of these words appear in the product description, the formula returns the result as a “Combo Product”. Otherwise, the formula returns the result as the “Single Product”.
    1. Now scroll down and click on the “Check Syntax” button to verify that the formula has no errors. Optionally, you can add the “Description”Help Text“, and “Handle the empty field” if you want. Click on the “Next” button to go to the next step.
    Salesforce Lightning FIND Function
    1. Select the relevant Field Level Security field. I have selected “Visible” in this case because I want it to be visible to everyone. Then, click on the “Next” button.
    Salesforce Lightning FIND Function Example
    1. Now, select the appropriate Page Layout where we want to be visible.
      • Click on the “Save” button to save the formula field.
    How to use FIND Function in Salesforce Lightning
    1. Once you have created the formula field, you can use it. Let’s look at an example:
      • Open the Products Tab, create a new product with the Product Description, and click Save.
      • Move to the Detail Section, where the Product Combo Type field displays the result of using the FIND() function.
    How to use FIND Function in Salesforce Lightning Example

    With this, we have learned how to use the FIND function to locate the position of a search string within a text field in Salesforce Lightning.

    Conclusion

    With this, we have concluded that the FIND() Function in Salesforce is a great and efficient way to find the position of a search string within a text. In addition, we learned the syntax and various real-world business examples of the FIND() function.

    Moreover, we covered the process of using the FIND() function in Salesforce Lightning.

    You may like to read:

    Agentforce in Salesforce

    DOWNLOAD FREE AGENTFORCE EBOOK

    Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

    Salesforce flows complete guide

    FREE SALESFORCE FLOW EBOOK

    Learn how to work with flows in Salesforce with 5 different real time examples.