1

I am writing an Inbound Email Apex Handler.

My situation is that whenever we get a reply from a client through email to salesforce, I only want to parse through the mail that was sent now and not the complete email thread.

Any idea, how I can do that?

@AjayGupta , I tried this string and it is not working -

Checking third timeOn Fri, Aug 21, 2015 at 12:03 AM, kaushik ray wrote:> Checking again.>> On Thu, Aug 20, 2015 at 11:59 PM, kaushik ray > wrote:>>> Hi Support,>>>> Thanks for this.>>>> I had a very good experience using the product. I was able to use it with>> out any issues.>>>> Thanks,>> Ray>>>> On Thu, Aug 20, 2015 at 11:55 PM, Salesforce Developer <>> abc@gmail.com> wrote:>>>>> Hello,>>>>>> How are you. I hope you are doing good.>>>>>> I just wanted to get a feedback about your past one month of usage.>>>>>> Do let me know how I can help.>>>>>> Thanks,>>> Support>>>>>>>>> _____________________________________________________________________>>> Powered by salesforce.com>>> http://www.salesforce.com/>>>>>>>>>

Update 2

I tried this mail, but still was not able to get correct result

Mail 2 :: Hello you still like my product.!!! Thanks def On Sun, Aug 23, 2015 at 1:16 AM, kaushik ray wrote:Hello nice meeting you again. Mail 1Thanks,abcThanks,Ray

3

I have written a custom logic to solve this problem for you(@ray) by spliting the response into parts using regular expression \\w{2} \\w{3}, \\w{3} \\d{2}, \\d{4} at \\d{1,2}:\\d{2} [PA]M, .*:, please check and try to execute this in your sandbox to test it:

String parseResponse(String message){
    List<String> splitResult = message.split('\\w{2} \\w{3}, \\w{3} \\d{2}, \\d{4} at \\d{1,2}:\\d{2} [PA]M, .*:');
    if(splitResult.size()>=2){
        return splitResult[0];
    }
   return message;
}

Call this method and pass the email.plainTextBody as parameter to parseResponse() private method as declared above in your Inbound Email Apex Class and received response will contain only current message not trailed complete email.

Let me know in case of any other help!!

  • Can you also explain how this is working the split line. That will be helpful – Kaushik Ray Aug 19 '15 at 13:30
  • I tried this but it is still taking the complete thread of mail. I tried to reply from my gmail – Kaushik Ray Aug 19 '15 at 13:43
  • I have also tested it using gmail email account, it is working fine , could you please paste content of email thread? – The Ajay Gupta Aug 19 '15 at 13:46
  • I tried this - second mail On Thu, Aug 20, 2015 at 4:27 PM, kaushik ray <abc@gmail.com> wrote: > tesing mail helli > – Kaushik Ray Aug 20 '15 at 10:59
  • it gave me the initial mail as well to which i replied – Kaushik Ray Aug 20 '15 at 11:00

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.