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.

1 Answer 1


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(' - ');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .