In my org I've set up an automatic process that sends email messages with the Custom template (with the HTML) to the contact. It has triggered similar code:
OrgWideEmailAddress addr = [select Id from OrgWideEmailAddress where Address = 'email@example.com']; EmailTemplate template = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'CUSTOM_HTML_TEMPLATE']; List<Messaging.SingleEmailMessage> composedMessages = new List<Messaging.SingleEmailMessage>(); Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setTemplateId(template.Id); email.setWhatId('5001G00000dZrHh'); email.setOrgWideEmailAddressId(addr.Id); email.setTargetObjectId('0031G00000rsMgZ'); composedMessages.add(email); Messaging.sendEmail(composedMessages);
Where WhatId is the Id of the Case, where messages were sent from and TargetObjectId - is the Id of the receiving Contact.
Until 1st of February 2019 both Activities and HTML Email Statuses were created, but then HTML States stopped being inserted. Even though receiver Contact receives the message, and it is listed in a Case Emails, and Contact Activities.
What I've tried:
1) Sending email message to the same contact directly from case manually using VisualForce interface. HTML Status was created with the Activity for the Contact.
2) Sending email message without setWhatId() method. HTML Status was created with the Activity for the Contact. But, obviously, message was sent without filling crucial information from the Case.
3) Tried to add
to the code above, but it didn't help me.
As a last resort, thinking about trying to do this without setWhatId() but with editing substring from the html/text body directly with values from the queried case fields, but it won't be a smart solution.
Thanks in advance!
Typical situation in a Contact page, when executing this method from the console. No HTML Status, but there is a Activity record: