FIND() Function in Salesforce

In this Salesforce tutorial, we will learn how to find the position of the search text string in the text using the FIND function in Salesforce. In simple words, we will learn the syntax of the FIND function in Salesforce and we will also see some real-world business scenarios of the function.

While working in a USA-based IT company that uses Salesforce for CRM tools. I got a task to examine customer reviews and based on it handle the cases situation that are urgent.

For this, 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.

What is Salesforce FIND() Function

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

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

FIND(search_text, text [, start_num])

Here are 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 expressions in which you are searching the substring.
  • start_num: The start_num parameter specifies the number from which it starts the searching process. And this search process always starts from the left side of the string to the right side of the string.

Moreover, there are some considerations that we must keep in your mind while 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 the zero if you are using the Find Function and doesn’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 that contains the website name the start_num parameter acts differently because in the website name, 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 display 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. negative number.
  9. No Result Cases: If the Find Function does not return the search result the zero is displayed in the field.
  10. Optional Parameter: In the salesforce Find Function the start_num parameter is optional. The function uses one or 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 with any other field type as an argument.

And if you are passing the simple text to the text parameter of the function make sure it must be enclosed in the single or double quotation marks. Furthermore, this Find Function returns the result in the form of a number that indicates the position of a string within the text parameter.

Let’s see a small 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 general introduction of the FIND function with its syntax and various important consideration. We have also learned just a small example to deeply understand it.

See also  OR Function in Salesforce

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

Read: GETSESSIONID() Function in Salesforce

How to use the FIND() Function in Salesforce Lightning

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 in a sales company and want to determine whether the product is a single unit or a combo by using the FIND Function of Salesforce on the bases of the product description.

So for this, you search for similar terms like “combo“, “bundle” and “package” in the product description, and on the bases of this, you divide the product into two different categories “Combo Product” and “Single Product”.

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

Step 1: Login to the Salesforce account first if you are not in Lightning mode, move to Salesforce Lightning. Once you reach the Salesforce Lightning page, click on the “Gear” icon located on the right side, and from the dropdown click on “Setup”.

FIND Function in Salesforce

Step 2: After moving to the setup of the current app, click on the “Object Manager” located at the navigation bar next to the Home Tab.

FIND Function in Salesforce Example

Step 3: Now, you are on the object manager page and here you will see the list of multiple custom and standard objects, search for the object in the “Quick Find Search” box on which you want to use the FIND function. As I define 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 click on it.

Step 4: On the click you are redirected to the product object page, move to the Details Section on the left side of the page and click on the “Fields & Relationships” option. Once you click on “Fields & Relationship”, you will see all the items sorted by the Field Label, but if you want to create a new formula field where you can use the Find Function, click on the “New” button.

FIND Function in Salesforce Lightning Example

Step 5: As you click on the new button, you will get the list of the multiple field types, select the one from the list that you needed. As you are going to use the FIND function, you need the “Formula” field type for this. So, I have selected the “Formula” field type. Then, click on the “Next” button, to move to the next page.

Salesforce FIND Function

Step 6: After clicking the next button, you will move to the page where you have to choose the output type. Here, we first enter the information by filling out the “Field Label” and “Field Name”. In this scenario, you can enter the “Product Combo Type” as the field label and then click on the “Field Name” box which automatically filled up.

Step 7: Now, you have to choose the data type for the field in which you want to get the result. Here, you have to choose the Text data type according to the scenario, you can choose any other as per the requirement. So, for this, check on the radio button next to the “Text” data type and get the return of the formula in text format. Click on the next step, by clicking on the “Next” button.

Salesforce FIND Function Example

Step 8: With the click of the next button, you redirect to the advanced formula page. 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 the text function 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 the IF statement that checks the field “Product_Description__c” and try to find the position of the search text string such as ‘bundle’ or ‘combo’ using the FIND() function of Salesforce.
  • If one of these words is found in the description of the product the formula returns the result as a “Combo Product”. Otherwise, the formula returns the result as the “Single Product”.
See also  Salesforce ISOWEEK Function

Step 9: Now scroll down and click on the “Check Syntax” button, to verify that the formula has no error. Optionally, you can add the “Description”, and “Help Text” as well as “Handle the empty field” if you want. Click on the “Next” button to go to the next step.

Salesforce Lightning FIND Function

Step 10: On clicking on the next button, you get a page to set up the “Field Level Security” and from here choose the user profiles to whom you want to grant the field-level security edit access to the field. If not added the field level security, the custom formula field that we have created not shows on the unselected profile.

You can check the checkbox next to the “Visible” option located at the top. If you want to visible this custom field for all the profiles. Click on the “Next” button to proceed to the next step.

Salesforce Lightning FIND Function Example

Step 11: In this step, choose the “Page Layout” where you want to add the custom formula field. If you do not select a layout, the field will not appear on any pages. To save the advanced formula field with the FIND function, click on the “Save” button.

How to use FIND Function in Salesforce Lightning

Once you have created the formula field, you can use the formula field. Let’s look at an example:

  • Open the Products Tab and create a new product with the Product Description and click on 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 find the position of the search text string in the text in Salesforce Lightning. Next, we will move ahead and understand the procedure of using the FIND function in Salesforce Classic.

Read HYPERLINK() Function in Salesforce

How to use the FIND() Function in Salesforce Classic

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

Suppose, you are working as an event organizer and you want to categorize the contacts using the FIND Function in Salesforce on the bases of the contacts highlight.

For this, you can search some specific terms such as “speaker”, “sponsor”, and “VIP” in the contact highlight, and on the bases of this you can categorize the contact in different categories “Speaker”, “Sponsor”, “VIP”, and “Regular”.

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

Step 1: First, log in to the Salesforce account, if you are logged in to the Salesforce Lightning move to the Salesforce classic edition. For this, click on the “Profile Avatar” and from the dropdown, click on the option “Switch to Salesforce Classic”.

FIND Function in Salesforce Classic

Step 2: Now, click on the “Setup” option located at the top right side of the page.

FIND Function in Salesforce Classic Example

Step 3: After clicking on the setup page, scroll down to the “Build” section and then click on the “Customize” dropdown option then from the list of all the salesforce objects, search for the object in which you want to use the FIND function. As I define in the above scenario I want to categorize the contacts. So, I searched for the “Contact” object and click on it.

Step 4: Once you click on the contact object you will get the list of multiple options available in the contact object and from this option, click on the “Fields” option as you want to create a new formula field where you can use the Find Function.

Salesforce Classic FIND Function

Once you click on the field option, the contact field page is opened, now move to the bottom of the page at the section name “Contact Custom Field & Relationship”. Click on the “New” button to create a new custom field.

Salesforce Classic FIND Function Example

Step 5: As you click on the new button, you will get the list of the multiple field types, select the one from the list that you needed. As you are going to use the FIND function, you need the “Formula” field type for this. So, I have checked the checkbox next to the “Formula” field type.

See also  LEN Function in Salesforce | How to calculate length of a text string in Salesforce

After selecting the field type, click on the “Next” button to move to the next step and fill up the details of the newly created field.

How to use FIND Function in Salesforce

Step 6: Now, you are on the choose output type page here you have to enter the information related to the newly created field and choose the field related to the output type. So, here you have to first enter the information such as “Field Label” and “Field Name”.

And as per the scenario, I enter the field label as “Contact Category” and when I click on the field name box it gets automatically filled up.

Step 7: As I mentioned above you also have to choose the data type for the field in which you want to get the result. In this scenario, I choose the Text data type by checking the radio button next to the “Text” data type and getting the return of the formula in text format. You can choose any other as per your need. After that, click on the “Next” button to move to the next step.

How to use FIND Function in Salesforce Example

Step 8: You will now navigate to the advanced formula editor. Now enter the formula in the advanced formula editor to determine the categorize the contacts using the FIND() function.

IF(FIND('speaker',  Contact_Highlight__c ) > 0, 'Speaker', IF(FIND('sponsor',  Contact_Highlight__c ) > 0, 'Sponsor', IF(FIND('VIP',  Contact_Highlight__c ) > 0, 'VIP', 'Regular')))
  • Here, we use the IF() Function to categorize contacts based on the field “Contact_Hightlight__c”.
  • The function checks if the specific word ‘speaker’ is found and assigns the contact category as “Speaker”.
  • In the next IF statement if the specific word ‘sponsor‘ is found assign the contact category as “Sponser”.
  • In the next IF statement if the specific word ‘VIP’ is found assign the contact category as “VIP”.
  • In all other cases, it assigns the contact category as “Regular”.

Step 9: To verify the above-written formula, that is error-free, click on the “Check Syntax” button located under the advanced formula editor. If there is no syntax error you will get the message “No syntax errors in merge fields or function”. But if there, is an error you will get an error message on the screen.

Step 10: You can also define the “Description” and “Help Text” as well as “Handle the empty field” if you want. After that, click on the “Next” button to move to the next step.

How to use FIND Function in Salesforce Classic

Step 11: On clicking on the “Next” button, the “Field Level Security” page is opened. Now configure the field-level security by choosing the profiles to whom you want to grant the field-level security editing access. If you have not selected the profile this specific field will be hidden from all the profiles.

As I want this field to be visible on all the profiles, check the checkbox next to “Visible”. Click on the “Next” button to move to the next step.

How to use FIND Function in Salesforce Classic Example

Step 12: The “Add Page Layout” is opened, choose the page layout that must have a newly created custom formula field. After that, click on the “Save” button.

Use FIND Function in Salesforce Classic

Once you have created the formula field, you can use it. Let’s see an example to check how it works:

  • Open the Contact Tab and create a new contact with the field Contact Description.
  • The Contact Category field, which displays the result of the FIND function, appears when you click on the Detail Section.
Example of FIND Function in Salesforce

With this, we have learned how to use the FIND function in Salesforce Classic.

Conclusion

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

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

You may like to read: