+ Start a Discussion
abhinav sarraf 1abhinav sarraf 1 

how can i create letter head in apex code

Hi ,

I have a requirement to send an email through code and I need to create letterhead in it. Is there any way to do it?
Best Answer chosen by abhinav sarraf 1
EldonEldon
Please refer this link https://krishhari.wordpress.com/2013/09/03/dynamically-populating-custom-html-email-template-content-in-force-com-with-custom-dynamic-data-using-apex/

All Answers

EldonEldon
Hi Abhinav 

You can use letter head in your mail from apex like below,
 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
EmailTemplate etemplate = [SELECT id,name, subject,HtmlValue FROM EmailTemplate where name='abc'];
mail.setTemplateId(etemplate .id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

For more info regarding branding your emailtemplate refer 
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_brandtemplate.htm

Regards
NagendraNagendra (Salesforce Developers) 
Hi Abhinav,

Try to use the setTemplateId field of Mail for achieving the above requirement.

Purpose of SetTemplateID: ID Of The The Template To Be Merged To Create This Email. You Must Specify A ValueFor SetTemplateId , 
SetHtmlBody , Or SetPlainTextBody . Or, You Can Define Both 
SetHtmlBody And SetPlainTextBody .
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
EmailTemplate et=[SELECT id,name, subject,HtmlValue FROM EmailTemplate where name='xyz'];
mail.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Please let us know if you need anything else.

Kindly mark this as solved if it's resolved.

Regards,
Nagendra.

 
abhinav sarraf 1abhinav sarraf 1

Hi Nagendra/Eldon,
What if the content is dynamic?

I know this way but i need the other way of it. as i need to set the data as well.

Regards,

Abhinav Sarraf 

EldonEldon
Please refer this link https://krishhari.wordpress.com/2013/09/03/dynamically-populating-custom-html-email-template-content-in-force-com-with-custom-dynamic-data-using-apex/
This was selected as the best answer