0

I am using the following code to send an email to user using HTML template. This issue which i am facing is i am getting email but the body of the email is blank. Am I doing any mistake in the code.

List<String> sendTo = new List<String>();
EmailTemplate et = [SELECT Id,Subject, HtmlValue,Body FROM EmailTemplate WHERE Name =:'MyTemplate'];    
String subject = et.Subject;
subject = subject + ' '+ p.Name;
sendTo.add(p.Request__r.Reviewer__r.email);
sendEmailSet.setToAddresses(sendTo);
sendEmailSet.setSubject(subject);
String emailBody = et.HtmlValue;
emailBody = emailBody.replace('{!Request__c.Link}', URL.getSalesforceBaseUrl().toExternalForm() +'/'+p.Id);
sendEmailSet.setHtmlBody(emailBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { sendEmailSet });
  • Is your template an HTML template? – manjit5190 Sep 23 '15 at 20:09
  • @manjit_singh yes its HTML template. – Tamil Sep 24 '15 at 12:39
  • Does Name =:'MyTemplate' work? I think the ":" is for referencing a variable, but you are already passing a hardcoded template name string. Can you do a debug on the emailBody string to see what it prints? Also, I don't see where sendEmailSet is defined. – Harmon Feb 6 '16 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.