I saw that most of the time all the Salesforce developers face an error where the client enters inaccurate data that has lots of unnecessary spaces.
Due to this, the user faces problems in searching, decision-making, inconsistent data entry, missed opportunities, etc.
So, I decided to overcome this problem, I started searching and found that in Salesforce we have a function named “TRIM” that removes the extra space and makes the data consistent and reliable.
TRIM in Salesforce is a handy text function that removes extra spaces from your data so your fields stay clean, searchable, and consistent.
In this article, we will learn about TRIM() function in Salesforce. When to use it, and how to use it in formulas, validation rules, and real‑life scenarios.
What is TRIM() Function in Salesforce
TRIM is a text function that removes spaces and tabs from the beginning and end of a text string. It also helps you clean up messy input so reports, searches, and integrations work as expected.
In simple words, if your data has extra spaces at the start, end, or in between words, TRIM helps you clean it so everything stays consistent.
The syntax of the Salesforce TRIM function is as given below:
TRIM(text)
Here, the text parameter specifies the expression or a field that you want to trim.
In addition, you can say that the TRIM function removes the spaces, making inconsistent data with spaces valuable and clean when extracting the data from external systems, spreadsheets, etc.
Let’s see an example of the TRIM function to understand the function better:
Assume a scenario, you got a task of importing all the contact details of the clients from an external spreadsheet. After importing it, he observed that when he searched for the client’s name he did not get the client’s contact details but the client is in the record.
After spending time, he figured out that there is an issue of extra spacing in the client name, some of the client names have leading spaces and some of them have trailing spaces.
To solve this, he found that there is a Salesforce TRIM() Function, so he decided to try it. Below, is the automatic formula logic for the scenario:
TRIM(Name)
With this, we have learned about the Salesforce TRIM function with syntax. In addition, we have seen a small example related to the function for a deep understanding of the topic.
How to use TRIM Function in Salesforce
Let’s see the steps on how to use the TRIM function in Salesforce to get the solution of the defined scenario.
- Go to Object Manager.
- Click the Gear icon in the top right and select Setup.
- Click Object Manager and open the Campaign object.
- Create a formula field.
- Go to Fields & Relationships and click New.
- Select Formula as the field type and click Next.
- Enter Field Label: Description Without Spaces (Field Name will auto‑populate).
- Choose Text as the formula return type and click Next.