Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to have users' email replies to case notifications attached to that case as a case comment? I've looked pretty much everywhere, and even asked Salesforce support but no luck, they just say you need custom coding but don't say where to start. Thanks!

share|improve this question
up vote 4 down vote accepted

Yes. Assuming you can forward a mailbox, you can do this with very little code.

  1. Enable Email-to-Case (On-Demand) with a Routing Addresses if you haven't already,

  2. Setup > Customize > Cases > Email Messages > Triggers,

  3. Create a new trigger; here's an example to get you started:

    trigger InboundCaseComment on EmailMessage (before insert) {
      List<CaseComment> comments = new List<CaseComment>();
      for (EmailMessage message : {
        comments.add(new CaseComment(
          IsPublished = true,
          ParentId    = message.ParentId,
          CommentBody = message.FromName + '\n' + message.TextBody
      INSERT comments;

Just be aware, you may need to tweak your configuration to avoid dual notifications now :-)

Edit: just did a sanity check per your comment... mine catches incoming replies ok: response case comment

So when the case owner sends emails, they're "from" the routing address which has a dedicated mailbox, eg The customer responds to the same. Your mail system must forward that mailbox to something like

routing addresses

Reconfirming with the screenshot below, the nice short Email-to-Case address needs to be selected (From) when sending emails. Hopefully this addresses your comment about the users' send-to address.

from email-to-case address

From an engineering point of view, this whole function is pretty bang-bang out of the box. I'm surprised Salesforce don't crow about it more.

share|improve this answer
thanks for the help. I tried it, and it does add the initial notification email to the case but the the incoming replies. thoughts? – user988 Feb 6 '13 at 0:07
can you triple-confirm for me that you have On-Demand Email-to-Case configured? – bigassforce Feb 6 '13 at 0:34
Yes I did confirm that my Email on demand is set up, and i put the routing address as my own email. I used the exact same code and generated a notification and replied to it. It just went to my email and not added to the case. don't know what's going on. :-( – user988 Feb 6 '13 at 0:49
oooh.. I know, i am so close i can almost taste it! I see what you mean now! i replied to that ugly email service address and it attached!! Now i just need to figure out how to make that appear in users' "Send To" field in Outlook! – user988 Feb 6 '13 at 1:18
Ok. Awesome. Thank you so much for the help! Really appreciate it! :-) – user988 Feb 6 '13 at 3:30

You would need to develop code around the EmailMessage object.

Basically, the idea would be a trigger that takes the reply ("BODY"), and copies that into the parent case comment.

share|improve this answer

Everything looks ok but do one thing -

Setup your email mail box email forwarding setting.

Set email as : email-to-case routing address

It helps when customer reply on this mail. It will automatically add case comment to this particular case

share|improve this answer
Hi Amit. For your answer to be well rated please allow me to suggest: proper punctuation (periods at the end of sentences), proper case (capital letters at the beginning of sentences), screen shots of what you are suggesting, removing the signature line. This last one may seem odd if you've used other forums, but is accepted practice in Stackexchange. – Peter Sep 18 '13 at 15:31
Hi Peter. thanks for your kind suggestion. actually my English is not so good. – Amit Katre Sep 18 '13 at 15:53
Your english is fine. Being bilingual I know it can be daunting to wade into a dicussion in a foreign language, but you only improve in a language by using that language (either spoken or programming), so good on you for giving it a go. :-) – Peter Sep 18 '13 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.