Loading

Considerations when multiple spaces are used in Text or Picklist fields

Publiseringsdato: Oct 13, 2022
Beskrivelse
Salesforce does not display extra spaces between two words. This might cause confusion when viewing the records or when using report filters.

If you type multiple spaces in a text field like this:
Last NameLast        Name
...when viewing the record details you won't be able to see them:
 
Account Namesalesforce.com
NameLast Name

There are a few things to consider around extra spaces in text fields.
Løsning
Please note that the data displayed in the user interface is rendered in HTML. HTML treats whitespace characters (spaces, tabs, and newlines) differently from ordinary characters. In general, a single whitespace character, including newlines, or a sequence of whitespace characters are treated as a single space and leading/trailing whitespace is eliminated.

That being said, extra spaces between words will be saved to the database and you can still see them in the edit page of the record. This could potentially cause undesired behaviors.

You should ensure that only quality data is entered in your organization, this includes avoiding multiple spaces between words.
There are a few things that can be done to prevent issues:
  • Data Quality control before importing it to salesforce (i.e. make sure the data files uploaded are correctly formatted and do not include bad data).
  • Create Apex Code to make sure the data introduced is processed correctly.
  • Create Workflow Rules for the same. Please see TRIM() function in this article: Formula Operators and Functions I – Z

Some specific scenarios where you could find unexpected behavior:

  • Long text area fields: You may want to type in pseudo-code, please note that the same rules will apply. The details page of the record will not display the indent style you create while typing but that style will be there if you click 'Edit' on that record.
  • Picklist values: Note that picklist values will also show the same behavior in relation with extra spaces, you can type them and they will be stored but when viewing the record the details page will not render them.
  • **Report filters: As mentioned previously, the extra spaces are stored in the database and it's only in the User Interface that you won't see them. Because of this, the Report will expect you to search the exact terms when creating a filter, including extra spaces, in order to retrieve the record(s). Example: A filter with "Last Name" -no spaces- won't retrieve the record we used above in the screenshots.
  • Lookup search: You'll need to use "Enhanced Lookups" to be able to find the record with a simple search. If you are not using "Enhanced lookups" you'll need to use wildcards (e.g. Last*) instead. More about enhanced lookups: Enabling Enhanced Lookups
  • Workflow & Validation rules: From the record detail there appears to only be a single space but when evaluating criteria for workflow rules and validation rules, the multiple spaces are recognized and may cause the criteria to not be met if the criteria only has a single space.
  • Chart filters in reports: If a report is grouped by a Formula (text) field where the result is a value that contains a trailing space, and that field is used as an axis in a report chart, if you click into the chart to filter the results, then no results will be returned. This is due to the trailing space being omitted from the filter. To resolve this, update the formula to remove trailing spaces.

**As a temporary workaround to the Report filters behavior you could change the filter
FieldName equals Word1 space-space-space Word2

for two filters:
FieldName contains Word1
AND
FieldName contains Word2


This is not recommended as the report filters with "contains" are less efficient performance-wise and you would be using 2 filters instead of 1 every time. For reports with many filters this won't be scalable.
Knowledge-artikkelnummer

000386982

 
Laster
Salesforce Help | Article