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
Ivaylo DimovIvaylo Dimov 

How to display letterhead Email Template using Apex

I am able to send an email from VF page, and am getting the emails with the proper text formatting, but I am not getting the letterhead associated to the email template that I am referencing. Is that even possible? Based on my research it seems like other folks have the same problem. My email template has letterhead that i would like to utilize, but it is not coming over with the email. Has anyone done anything similar?
 
EmailTemplate emailTemplate = [select Id, DeveloperName, HtmlValue, Body From EmailTemplate where DeveloperName = 'LTRO_Additional_Documents_Required'];
    //////////////////////////////////////////////////////        
           String htmlBody = emailTemplate.HTMLValue;
           htmlBody = htmlBody.replace('NewEmail', emailBody);
           mail.setHtmlBody(htmlBody);
    ///////////////////////////////////////
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 
NagendraNagendra (Salesforce Developers) 
Hi Dimov,

You can query the BrandTemplateId from the EmailTemplate object, and from there, you can query the BrandTemplate, which is in HTML form. You'll need to do some parsing via Dom.Document or some other means, but it is certainly possible to gain access to the letterhead.

For more informaion please refer to below link. Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
Ivaylo DimovIvaylo Dimov
Hi Nagendra,
Yes, I know that I can access to BrandTemplateId, but what I am struggling with is how to incorporate that with my code, so that when I send out an email from Apex, it is using the Branding associated with the template.I thought calling the template, would also call the branding that comes with it, but it is not. I did a ton of research only, but could not find a clear example of that other than what I already have.