Finding text strings in Salesforce Flow
Parsing, validating, or spotting a specific chunk of text inside record data comes up constantly. Lead routing based on an email domain pattern, data hygiene on a custom text field, pulling an identifier out of a description: it all lands on the same small set of Flow formula functions.
How string searching works in Flow
Apex gives you regex through the Pattern and Matcher classes. Flow does not; it relies on Formula functions. "Finding" a string in Flow means one of two things: getting the starting position of a substring, or checking whether a pattern is present at all. The functions that do the work:
FIND(search_text, text): Returns the position number of the first character of the substring.CONTAINS(text, compare_text): Returns a boolean indicating if the substring exists.LEFT,RIGHT, andMID: Used to extract the data once the position has been identified viaFIND.LEN: Essential for calculating bounds when performing dynamic string slicing.
Finding and extracting a substring
A common one: extracting a "Project Code" from a free-text "Description" field, where the codes are always preceded by PROJ-.
- Identify the position. Create a Formula Resource (Number) to find the start of the code.
FIND("PROJ-", {!$Record.Description__c}) + 5 - Extract the text. Use
MIDto pull the next 6 characters, assuming a fixed-length code.MID({!$Record.Description__c}, {!Find_Project_Code_Position}, 6)
Chain those two and you have a search that reacts to whatever comes in, with no Apex.
Pattern matching with formula logic
When FIND on its own is too blunt, combine it with IF or CASE logic to handle the shapes your data actually arrives in. Worth remembering when the casing is inconsistent: Salesforce string functions are generally case-insensitive, which saves you a step.
If you need tighter validation (making sure a string follows a specific alphanumeric sequence such as 'A123-B', for instance), check the format in a Flow Formula before you process it:
/* Formula to check if the string contains a hyphen */
CONTAINS({!TextVariable}, "-") && LEN({!TextVariable}) > 5
Handling nulls and edge cases
Nulls are where this falls over most often. FIND on a null field will not stop the Flow, but the results get strange if the rest of your logic assumes a character is there. Put a null check in your decision elements or assignment formulas.
- Decision element: check if
{!$Record.TextField__c}Is Null{!$GlobalConstant.False}. - Formula logic: wrap your
FINDfunctions in anIFstatement to return a default value or0when the search string is not found.
IF(CONTAINS({!$Record.Description}, "CRITICAL"), "High Priority", "Normal")
When to hand it to Apex
I default to Flow, but there is a ceiling. If you need true regular expressions (validating email formats, parsing awkward phone numbers, finding every occurrence of a pattern in a large blob of text), Flow formulas hit their complexity limit fast.
Write an @InvocableMethod instead. Pass the text into an Apex class, use the java.util.regex engine, and hand the result back to the Flow. The Flow stays readable and you still get the parsing you need.
Leave a Comment