You need to sign in to do that
Don't have an account?
need help for code
I have a trigger that takes incoming/outgoing case emails and makes a copy of the email body into the case comments. I have written some code to take out any of the reply history by looking for the string "From: " or "wrote: ". This is to take into account the various email clients and how they might reply back.
The idea is that when you reply back to an email it will either say:
From: abc@xyz.com
{email body here}
OR
On 9/5/12: johndoe wrote:
{email body here}
So the code will take anything before the From: or wrote:
if (em.TextBody.contains('From:')){myPlainText = em.TextBody.substring(0, em.TextBody.indexOf('From:'));} else if (em.TextBody.contains('wrote:')){myPlainText = em.TextBody.substring(0, em.TextBody.indexOf('wrote:'));} else {myPlainText= em.TextBody;}
The problem I'm running into is if different clients have been used in the reply messages with some using "From:" and some using "wrote: ". My code is looking for "From: " first then stops. If that "From: " was embedded in a bunch of replies using "wrote: ", then I would have taken a bunch of replies into my comments.
Is there a way to write the code so that it will look for whatever is highest on the string and then use that as "myPlainText".
Hi
Hope the below code helps:
Regards
Sam
maja madi
Thanks for the suggestion Sam, but I don't think this will work for me quite yet. What I'm looking for is something that looks for whatever comes first, "From: or wrote" then breaks it from there.