Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
A 3D magnifying glass highlighting data nodes to assist with finding text strings in Salesforce records.
Flow

Finding Text Strings for Entities in Salesforce: Flow Guide

How to locate and parse text strings in Salesforce record data with Flow Builder: the formula functions that do the work, the null cases that break them, and when to hand the job to Apex.

The short answer

Flow has no regex. Finding a string means FIND to get the position of a substring or CONTAINS to test whether it is there, then LEFT, RIGHT or MID to pull the value out. Null-check the field first, and hand the job to an @InvocableMethod when you genuinely need regular expressions.

Key takeaways Start with FIND, CONTAINS, and MID inside Flow Formulas. They cover 90% of business use cases. Keep formulas lean. Parsing hundreds of records means long formula execution times start to count against governor limits. Check for null or empty fields before manipulating a string, or you get runtime errors in your automation. When regex or complex parsing is non-negotiable, use Invocable Apex to bridge simple Flow logic and heavier string processing. Document the formula logic in the description field of your Flow Resources, so the next developer understands why the extraction works the way it does.

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, and MID: Used to extract the data once the position has been identified via FIND.
  • 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-.

  1. Identify the position. Create a Formula Resource (Number) to find the start of the code.
    FIND("PROJ-", {!$Record.Description__c}) + 5
    
  2. Extract the text. Use MID to 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 FIND functions in an IF statement to return a default value or 0 when 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.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment