My requirement is to extract specific string from a email subject like.

My email subject always like:

Fleet Invoice inv - account name

I need to extract account name from above subject line.

Always they use same specific template.


The Apex String class provides a lot of useful methods.

In your case, I'd use the substringAfter(separator) method to get the end of your String after the '-' character. Like this:

String accountName = yourSubject.substringAfter(' - ');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.