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
Michela BovioMichela Bovio 

EmailTemplateId field not always populated in the EMailMessage object

I'm trying to find who is the last user that used a classc email template in an email and I found that in the EmailMessage object there is the EmailTemplateId field that could help me
Looking at the EmailMessage object I find too few records having this field populated even if I know that in our org many users use email templates. 
 also read that that field is populated just if Lightning is enabled but our org is still in Classic so how is that possible ?

Any help on thi is appreciated
Thanks
Michela
AnudeepAnudeep (Salesforce Developers) 
Hi Michela, 

As per the documentation https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_emailmessage.htm EmailTemplateId is populated in Lightning Experience only.

Does any of your users have Lightning Experience User permission? 

What does UserInfo.UIThemeDisplayed() return for the user returned from your analysis?

It could be possible that EmailTemplateId is populated through Apex. Can you try inserting an EmailMessage with emailTemplateId, that should help confirm the behavior
 
// Add Email Message Relation for id of the sender
EmailMessageRelation emr = new EmailMessageRelation();
emr.emailTemplateId= '005B0000003qHvOIAU';
emr.relationId = '005B0000003qHvOIAU'; // user id of the sender
emr.relationType = 'FromAddress';
insert emr;

A similar discussion has happened here: 

https://salesforce.stackexchange.com/questions/285670/emailmessage-object-emailtemplateid-is-null

If this answers your question, please mark this as Best Answer so that it can help others in the future. Thank You!

 
Michela BovioMichela Bovio
Hi Anudeep 
thanks for your quick answer
We still didn't enable lightning for our users, just a few of us use lightning. None of the users that sent the emails having the EmailTemplateId field populated is using Lightning interface
We also don't use APEX for sending emails with templates
So I really don't understand why the EmailTemplateId is present on some email message
Michela
 
AnudeepAnudeep (Salesforce Developers) 
Hi Michela, 

Can you check if the template found using EmailTemplateId field is a default email template? Default email templates are generally used when send email quick action is used but again that looks like it is only available in LEX 

https://help.salesforce.com/articleView?id=case_interaction_send_email_quick_action_default_email_template_lex.htm&type=5

Anudeep
Michela BovioMichela Bovio
Hi Anudeep 
Thanks for looking at  this, I just checked and I found that it isn't a default email template 
Michela

 
AnudeepAnudeep (Salesforce Developers) 
Hi Michela, 

This looks strange. Can you try engaging Salesforce Support to investigate further?  Thanks

Anudeep