function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Email to Case: finding string within a text area



We are using SFDC email to case.

Is there a way to search a text area (body of the email) for a unique number and populate this to a field within the case object?


The unique number always follows this format e.g FY554077

(2 letters followed by 6 numbers).


Many thanks




You'll need to use a regular expression (string that is used to match another string) by using the Pattern and Matcher classes in Apex.


for example: 


String body = (your message body containing the #);

Pattern.compile('[A-Z]{2}\d{6}|[a-z]{2}\d{6}]'); //(for ex. this will grab BC849203 or bc948593)

String[] result = Pattern.split(body);


The result list will contain each substring of the String that matches this pattern.

You can learn about how to build a regex here:

And test a regex here:




If you are not familiar enought with Regex to know where in the exixting Case Apex code to place this snippet, then include the complete Apex case code and we can help you locate the snippet position.



Where do I put the field that I'm querying in this code?

The body of the email drops into a field called Description__c.


Thank you



mizael leemizael lee
🔸 GNU Bash (" target="_blank) - is an sh-compatible shell that incorporates useful features from the Korn shell and C shell.
🔸 Zshz (" target="_blank) - is a shell designed for interactive use, although it is also a powerful scripting language.
🔸 tclsh (" target="_blank) - is a very powerful cross-platform shell, suitable for a huge range of uses.
🔸 bash-it (" target="_blank) - is a framework for using, developing and maintaining shell scripts and custom commands.
🔸 Oh My ZSH! (" target="_blank) - is the best framework for managing your Zsh configuration.
🔸 Oh My Fish (" target="_blank) - the Fishshell framework.
🔸 Starship (" target="_blank) - the cross-shell prompt written in Rust.
🔸 powerlevel10k (" target="_blank) - is a fast reimplementation of Powerlevel9k ZSH (" target="_blank) theme.
Stella SallesStella Salles
However, if you use, you can spend your budget better and more efficiently by setting specific goals (Goal Setting) in Google Analytics or other measurement tools, and monitoring KPIs: (