My case is i want to send email with attachment in custom object using single email message using HTML Email Template (with letterhead).
Current condition i successed to make the email same like email template (HTML body) by using these methods:
email.setToAddresses(emailResults);
email.setTargetObjectId('0055D000001DHyJ'); //user id
email.setTreatTargetObjectAsRecipient(false);
email.setTemplateId(tem.Id);
But the problem is, fields in email template become blank. For Example:
Email template
Dear {!Invoice__c.Customer},
Result
Dear ,
I also try use .replace but it make email body become blank.
Is there any solution or workaround for this case?
Refference : http://hareeshgoudsalesforce.blogspot.com/2016/06/stop-sending-email-to-settargetobjectid.html
setTargetObjectId
being set to aUser
orContact
orLead
?