[SalesForce] Track which email templates are used on which cases

Our customer service agents are sending emails to customers from cases through the standard "Send an Email" page where they select a template. Often they edit the text before sending.

We'd like to track which email templates are used in which cases. (Background: This is a preparation for automating parts of this. The idea is to train an AI to propose and eventually send the correct template for new cases based on the customer's message and some metadata. To create training data for the AI, we need to track which email templates are used in each case.)

My first idea:

Add new text fields on Email Message that hold the Email Template's id and the unique name (Salesforce does not allow lookups to Email Templates). Then I re-build the "Send an Email" page as a Visualforce page and store the template id and unique name on the new Email Message every time one is sent. I could then use a "cases with emails" report to get the data. Optionally store whether the email text was edited before sending.

  • Pro: Only adds custom fields on Email Message, so storage usage is not a problem.
  • Cons: Have to re-build a standard page that is used with high frequency.

I'd appreciate all comments. How would you go about tracking email template usage?

Best Answer

In response to ataneja's question, here is how we did it:

  • We added the template id at the end of all text email templates, using a script. This means ids like "00X0J000002L0s5UAC" below the footer of each email template.
  • Add a text field "TemplateId__c" to Email Message.
  • In a beforeInsert trigger on Email Message, we search for the template id in the email text (all template ids start with "00X"). If we find it, we store it on EmailMessage.TemplateId__c.
Related Topic