function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MikeD13MikeD13 

Email Service: Email to Case Implementaion and ThreadID

I am in the process of setting up an Email Service to handle Email2Case. The service works when creating a new case, however, I'm having problems when trying to update existing cases.

I have a few questions:
1) Is there a standard format for the ThreadID. Example -  ref:[8 Characters].[8 Characters]:ref
2) How do I find a case by the thread ID? The thread ID appears to be a truncated version of the organization and case ID's but this seems odd to me. If it is, what is the formula for truncting the ID's (first 4 plus last 4 is what it looks like).

Thanks,
Mike
werewolfwerewolf
There is a standard format.  This AppExchange package will generate it as a custom field on Case:

https://www.salesforce.com/appexchange/detail_overview.jsp?id=a03300000059dqdAAA

Happy threading!
MikeD13MikeD13
Thanks! I submitted a case with this same question and still haven't heard back. I'm pretty sure I never would have guessed that formula in a million years. Is this documented anywhere or did someone (you?) just figure this out on their own?


paul-lmipaul-lmi
would you mind posting the format?  I'd rather do this with a regex than a custom field and SOQL query.
MikeD13MikeD13
Can you give me more information on what you plan on doing? I'd love it if I could avoid using SOQL but I'm not familiar with the method you are describing.

Baiscally, the formula is this:
[First 4 digits of the OrganizationID followed by all digits after the last zero].[First 4 digits of the CaseID followed by all digits after the last zero]

For example (I know they are not actual ID's):
Organization ID = 00DX00000ased23
Case ID = 00a40000000DDs2
Thread ID = 00DXased23.00a4DDs2

This is the pattern I used to determine whether or not an email was a reply (please let me know if there are any problems with this... I'm new to using resgular expressions):
Pattern.compile('ref\\:[a-z0-9A-Z]{5,}\\.[a-z0-9A-Z]{5,}\\:ref');
I did finally receive a response from Saleforce support regarding this issue. They informed me that it was not possible to retrieve a case using the Thread ID and suggested I retrieve the case using the Case ID. Wow!!! Ya think?!?! Let me just use the case ID that's in the.... oh, wait... they use the Thread ID in the emails... thanks for the help, Saleforce!!!!





paul-lmipaul-lmi
oh ok, so the only real benefit to adding this custom thread ID field is to obfuscate unique ID's from the customer.  we don't really care if they see our case ID's, as they are useless to any unauthenticated user anyways.

i think i'll keep my implementation using the case.id as the thread.

cheers!
werewolfwerewolf
You can use the case ID as your thread ID and that's equally valid, it's just that a lot of the auto-generated stuff like Autoresponse will create a thread ID.  The thread ID doesn't really obfuscate the org ID or case ID, as you've seen, it just shortens it, probably just to make that added portion in the subject and body a little shorter.
paul-lmipaul-lmi
indeed.  i opted to thread by way of the templates as i'd rather have the user prodivded subject over a potentially truncated subject line just to fit the thread id.  i'm pretty strict about custom fields in our org as well, so this all works nicely.  now if they'd only make it easier to debug quirks in these services rather than guess about what happens in the black hole between email being sent, and Apex code processing it.