We have issue in getting the EmailTemplate id from EmailMessage object . After we send email the emailTemplate Id is not populated. This email is sent using a template
List<EmailTemplate> lstEmailTemplates = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'XXXXX'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(lstEmailTemplates[0].Id);
mail.setSaveAsActivity(true);
//set addresses
mail.setToAddresses(toAddresses);
mail.setTargetObjectId(lsAcr[0].ContactId); // Any contact Id of your record
mail.setTreatTargetObjectAsRecipient(false);
mail.setUseSignature(false);
mail.setWhatId(caseId);
The field EmailTemplateId was added so that we can track which template was used for the email in Spring 19 release.
When we query EmailMessage object using the Id of the email sent we see that EmailMessageId is blank ?
Is our understanding incorrect on the usage of this field ?