Created By: Jose Carlos De Oliveira
Converts a string with accented characters (diacritics) into their standard equivalent version (ASCII); eg. José > Jose
Includes additional methods such as:
- Removing special characters keeping alphanumeric only, eg. O’brian > Obrian
- Replacing special characters with empty spaces, eg. O’brian > O brian
- Returning using proper case (first letter capitalised), eg. joe doe > Joe Doe
- Removing all spaces
String Normaliser
String Normaliser is a utility class originally developed to replace accented characters (diacritics) in names with their ASCII equivalents. Examples:
- Mélanie → melanie
- François → francois
- José → jose
- Iñaki → inaki
- João → joao
(All strings are returned in lower case to improve processing time by reducing the number of characters to iterate.)
Additional Functionality
The class has been expanded with several useful methods:
- Remove special characters while keeping alphanumeric only Example: O’brian → Obrian
- Replace special characters with spaces Example: O’brian → O brian
- Return proper case (first letter capitalized) Example: joe doe → Joe Doe
- Remove all spaces
Use Cases
This utility is especially useful for duplicate detection, such as:
- Comparing records in Matching Rules by populating custom fields (e.g.,
FirstNameASCII__c,LastNameASCII__c) - Searching existing Contacts/Leads in a Flow Query to avoid creating duplicates
Custom fields can be populated by:
- A Before-Save Flow
- An Apex Trigger when names are edited or records are created
A Batch Job can also be implemented to update all existing records in the org.
(The utility class is separated from the Invocable Action so it can be used directly in Apex. The test class includes both.)
Extensibility
The current diacritics map can be expanded declaratively by moving it to:
- Custom Metadata
- Custom Settings
Components in this package
StringNormaliser Utility Class
This utility class performs different string normalisations actions that can be combined within each other. Its methods can be called anywhere in Apex, such as Trigger or a Batchable class to clean Contact’s Name in bulk for existing records, for example.
Includes the following methods:
- removeDiacritics(String): replaces accented characters by the ASCII version using a hardcoded map. This class can be extended to use Custom Metadata records to define additional characters replacement – (scheduled for a next release)
- convertToProperCase(String): Capitalises the first letter of every word, similar to the PROPER() function in Excel.
- removeSpecialCharacters(String): Completely removes any characters that is not an alphanumeric value.
- replaceSpecialCharactersForSpace(String): Instead of completely removing the non-alphanumeric character, it replaces them for a empty spaces, O’Brian > O Brian
- removeAllWhiteSpaces(String): removes all empty space from string, for cases where a string needs to be compare with another string.
StringNormaliser Invocable Action
Apex Action to use in Flows to normalise x2 strings (eg. First Name and Last Name).
Inputs:
- “String 1” – Text
- “String 2” – Text
- “Apply Proper Case” – Boolean: Capitalises the first letter of every word, similar to the PROPER() function in Excel.
- “Remove special characters” – Boolean: Completely removes any characters that is not an alphanumeric value.
- “Replace special characters for a space” – Boolean: Instead of completely removing the non-alphanumeric character, it replaces them for a empty spaces, O’Brian > O Brian
- “Remove spaces” – Boolean: removes all empty space from string, for cases where a string needs to be compare with another string.
Outputs:
- Normalised String 1.
- Normalised String 2.
Installation Links
- Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04tJ7000000D8xn
- Production: https://login.salesforce.com/packaging/installPackage.apexp?p0=04tJ7000000D8xn
Source Code
Written by: Jose De Oliveira
