Dec 18, 2012

Formula: Ref Tag for Email-to-Case

If you're using Salesforce for customer service, chances are that you are using email from the Case object.  When you leverage the "Email-to-Case" feature, Salesforce will add to Case related emails a "ref:" tag.

Let's assume is configured as your company's email-to-case Routing Address.  A customer needs assistance with one of your products and sends off an email requesting assistance.

This tag is what allows Salesforce to automatically connect this email to the appropriate existing case.  If not found, a new Case is created and set up in accordance with the configuration of that Routing Address.

So when the customer sends the email above, requesting assistance from, you're email server or email client will be configured to forward messages sent to to the Salesforce assigned email address, which looks like this:

When the email address is forwarded to the Salesforce address highlighted above, the Salesforce email services look at the subject and body of the message for an existing "ref:" tag.  If one is found, the email is created as Activity History for the associated case.  If one isn't found, it looks at the configuration of the Routing Address and creates a case.  This is why it is important to not remove the tag from your emails; doing so could result in duplicate or unnecessary cases.

There may be scenarios where you need to know what the "ref:" tag for a Case is.  You might need to include this on e-mail templates for internally created cases for customers.  

How is this value constructed and what is the Salesforce Email-to-Case email service expecting?

If you take a look at a "ref:" tag, you'll see it follows this pattern:

To replicate this in a formula field, you can use this:

I've seen a similar formula on the forums, but I've added a LEFT($Organization.Id,15).  Without this, I was generating the first portion of the "Ref:" tag using the 18 character ID of my org.  The resulting "Ref:" tag did not match the "Ref:" tag from the email I received in prior testing.

Now you can use the new formula field on your Salesforce templates.  Alternately, you can follow this patter when developing your own Salesforce email handling services.