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.



- Add the TRIM() function in formula.
- In the formula editor, change Functions dropdown to TEXT to see text functions.
- Select TRIM and click Insert Selected Function.
- Replace the parameter with your field, for example:
TRIM(Campaign_Description__c)- Click Check Syntax to ensure there are no errors.

- Select Field Level Security for the formula field, then select the profiles to make the field visible to them. The field will be visible for the selected profiles in the Visible column.
- After selecting the profiles, click Next.

- In this step, we must select the field’s visibility on the object’s page layouts. In this case, we have created a formula field for the reports, allowing us to choose not to display it on the page layouts.
- Uncheck the page layout checkboxes to prevent the field from displaying on those layouts. After this, click on the Save button.

Once the formula field is created, you can use the formula field. Let’s see an example:
- Open the “Campaign” item, proceed to create a new campaign with the “Description” field, and save the campaign.
- Upon successfully saving the campaign, move to the campaign details page. Here you will observe the “Description Without Spaces” field, showing the outcome evaluated from the TRIM function.
Let’s understand with an example:
Imagine you have created a campaign, with the campaign description ” Join us for our exciting Summer Sale event !” and save it. So, for the campaign description ” Join us for our exciting Summer Sale event !” the Description Without Spaces formula field will show a cleaned version using TRIM.

With this, we have learned the utilization of the TRIM() function in Salesforce.
Conclusion
With this, we have learned about the TRIM() function in Salesforce . We have also learned the syntax and its practical applications. Additionally, we have learned how to efficiently utilize the TRIM function in Salesforce.
You may like to read the following articles:
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.