I am working on a email to case feature of case . When a customer sends a mail case is created inside our org and now from that case a send a mail(using Send Email Button in related list of case) a mail is sent to that customer and if in return if that customer reply to that mail in that thread with same reference id .. that content does not get attached to that case.. i don't know to implement this functionality.

Thanks in Advance

  • Have u confirmed if you have setup "Email-to-Case" section correctly under Setup | Cases ?
    – VarunC
    Commented Feb 6, 2015 at 17:52
  • How do i add an inbound email to an existing case ..?? i got the case number from the thread id Commented Feb 6, 2015 at 18:42
  • I've added details to do that with proper code highlightings
    – VarunC
    Commented Feb 6, 2015 at 18:55
  • Have you review the standard SFDC documentation on this? help.salesforce.com/apex/… Commented Feb 6, 2015 at 19:35
  • 1
    help.salesforce.com/apex/… This explains how the Reference ID works when users send emails directly from Case to End User and how their response gets threaded back to Case. Commented Feb 6, 2015 at 19:35

1 Answer 1


Step 1:

You can create a Formula Field on Case (say REF_CODE__c):

"[ ref:" + LEFT( $Organization.Id , 4) + RIGHT( $Organization.Id , 4) + "." + LEFT(Id, 4) + RIGHT( Id , 5) + ":ref ]"

Step 2:

In your Email Template (which you are using to send Emails to customer), you can include the field REF_CODE__c in either Subject or Email Body like this Subject: xyz case subject {!REF_CODE__c} OR in Email Body: just place {!REF_CODE__c} code in anywhere may be end of the email body section.

EDIT: There are many solutions posted over stackexchange itself for computing the Reference Code. One such link is here and there is already an answer marked on this:

Also I found couple of Ideas to support this Reference COde be part of Standard Salesforce Field on Case Object:

  • 1
    Can you please provide where is this documented the format of the Ref Code ID. I'd worry if SFDC changes format of this ID in future will this still work? For example all the folks who hard coded these types of values in their JavaScript based on old SFDC DOM know that stuff like this is subject to change at SFDC's will. If users use the standard SFDC Case Email Response button in SFDC it will automatically attach the REF ID to all emails. Commented Feb 6, 2015 at 19:40
  • Sry guys, I don't think there is any official documentation to support this .. I'm copying this solution from the information I had gathered in past from a salesforce executive and we've been using this formula nowadays in our crm. And Yes very correctly stated, if however you use Standard Reply button on Email on Case, SFDC will attach this code. I'll be updating the answer with more information about this formula evaluation. Thanks for querying on this @CoryCowgill :-)
    – VarunC
    Commented Feb 6, 2015 at 20:29

You must log in to answer this question.

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