Background: I am trying to implement Email2Case as efficiently as possible for my company, and one of our current issues/gripes with it is that Salesforce has no native ability to parse only the "newest" portion of the message into a new reply. The result is that lengthy back-and-forths end up becoming very long, scrolling walls of text - cluttering page space and just impacting the experience.

Partial Solve: I'm able to solve this easily in automated response emails by adding a unique friendly string to the top of the templates, and then using String.SubStringBefore() to only grab any new text that exists above my friendly string, but when users send emails from the native Send Email action on a Case there is no native option that I can find to add custom text to the email body.

Already Considering: I can add thread Id to the body natively through Settings, which I could then search for and stop on the first occurrence of, but this is messier because then I'd need two separate logic blocks to check for different "end of message" strings and handle them differently.

I'm not opposed to this, just trying to first explore the option of being able to add my EXISTING "friendly string" to all messages before they go out.

I thought I could just modify the String in the before Insert context on the EmailMessage object, but according to this: EmailMessage before insert trigger not working as expected? , it doesn't work like that.

Ultimate Question: Is there some way that I can programmatically "catch" an email message before its sent and modify the body to append a string?

1 Answer 1


I'm not aware of a way to do this with the standard "send email" on case as you have no access to that email before it actually sends out.

I've done this type of thing before, but I had a custom lightning component that users used to send emails from cases on which gave me complete control of the email before I sent it out in the code. This obviously adds a lot of code/customization to something that is already out of the box.

Otherwise, you could attempt to add more aggressive parsing to figure out what's the new part of the email chain to your already existing e2c logic. You could take the most common email clients and see how they separate chains to clean the email message up or look at other resources for best regex patterns or solutions.

https://datascience.stackexchange.com/questions/19390/extracting-individual-emails-from-an-email-thread https://www.mailgun.com/blog/open-sourcing-our-email-signature-parsing-library/

You must log in to answer this question.

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