I have a requirement to create case for specific subject email.I wrote an email service working well.

But now i try to capture some values from email body and need to updatein specific field.


Invoice Total Amount: 658.81 USD(includes taxes, shipping and handling)

I will try to use like emailBody[0].substring(22);

But, amount value will change accordingly.So i try to use string functions like ends with But i'm not able to achieve.

  • The subject will always be the same? Only the amount will change? Commented Aug 17, 2017 at 14:38
  • Yes only amount will change in the above template
    – Pavan tej
    Commented Aug 17, 2017 at 14:39

1 Answer 1


If you're sure the subject will never change except for the amount, you should use the substringBetween(open, close) method of the String class. You can use the ':' character as open tag and 'USD' as close tag.

Then, you can use the trim() method of the String class to remove any leading or trailing white space characters.

Here's the code:

String amountStr = subject.substringBetween(':', 'USD').trim();
  • Works as expected mine is currency field converted to decimal.
    – Pavan tej
    Commented Aug 17, 2017 at 18:08

You must log in to answer this question.

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