Proper Application Of The Grocery Store Method
When you go to the supermarket, do you acquire everything that is in the store? Likely this is not the case, as with each trip, you take only what you need, and leave what you don’t. This methodology can also be used in the non-physical space with technology, and when it comes to Salesforce, a perfect use-case is with formula fields (and their derivatives such as Validations, Flows, etc.) If we take for example this sample field that produces the following output (made up of the Record Name and Product) , there may be a case where you would want to strip out part of this to use on its own, or to be used as a portion within another field.
Example Field Name: Object_Reference__c
Output: Company Name - Green Apples
Perhaps you would want to extract the Company Name only (or a portion of this), or instead utilize the whole (or portion) of the Product field. Two ways to accomplish this can be done via a Formula/Text field using the (i) TRIM or (ii) LEFT/RIGHT functions. Looking at this in more detail, should the requirement be to extract only the Company Name for example, this can be accomplished by using the following statement:
LEFT(Object_Reference__c, FIND("-",Object_Reference__c))
In using this as the formula field, the output will now be “Company Name “, as only the information to the left of the ‘dash’ separator (-) will be the result. If you take a closer look at the specifics of the output, you’ll notice that there is a space to the right of ‘Name ‘. To eliminate this extra space so you're left with only the Company Name, just add the number of characters you wish to be removed. In this case, the following statement will produce the output as “Company Name” (without the space).
LEFT(Object_Reference__c, FIND("-",Object_Reference__c) -1)
If you wanted to instead extract the Product Name, then you would just need to slightly modify your statement to use the RIGHT function, which would produce the value “Green Apples’. Like the prior statement, be sure to account for the spaces via the -1 suffix. You can also accomplish a similar formatting change using the TRIM function. In this example, let’s say you wanted to remove the first 4 characters from the Object_Reference__c field’s output, the following statement would return “any Name - Green Apples”.
TRIM(RIGHT(Object_Reference__c , (LEN( Object_Reference__c) - 4)))
For extracting the end of the statement, the ‘TRIM(LEFT’ option will remove a set limit of characters to the end of the statement. We would just need to replace ‘RIGHT’ with ‘LEFT’ on the prior statement, and set the total number of characters to the end of the statement. So, if we used ‘-7’ to the end of the formula, the result would be “Company Name - Green”. The TRIM function can also be used in many other ways in connection with other basic formula statements in producing automated values. One such use-case is in the proliferation of email formats. Let’s consider that your Company has standardized its email addresses by using the First Initial of the ‘First Name’ and the entire Last Name for the naming convention of the email address (before the ‘@’ symbol). In this case, you could write the following statement using the TRIM function to accomplish this:
TRIM(LEFT(First_Name__c,1)) & (Last_Name__c) & "@company.com"
These represent a few examples of ‘trimming the fat’ from your fields to use in other areas of your application(s) to further eliminate manual actions. There are many uses of the TRIM function for a myriad of situations when you need to replace (or remove) spaces (i.e. Email), combine fields to form a specific string of text (Custom Field Definition) or extract only the characters needed for use in reports (i.e. first few characters of a Postal or Zip Code). While there may not currently be a requirement for this function, there will no doubt come a time when you will want to enhance your analytics or automate certain parts of your Salesforce applications for which the TRIM function can deliver the results you need... when you need it.
Title image by Mooris.de / Blockitecture Art Deco










