• Hobbele12354624
  • 0 Points
  • Member since 2008

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
Hi there.
I have the following apex class that is to send an email which includes
a visualforce email template.
Unfortunately when I include setTemplateID method that
has a parameter of the exact VF email template I want to send,
I get false. Everytime. If I remove the setTemplateID, I get an email,
minus my template.
Can anyone help me out please?
Here is my apex class
public class EmailCardListController {
public Boolean emailSent { get; set; }
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'jbloggs@salesforce.com'};
    public PageReference sendMail() {
        mail.setSenderDisplayName('Salesforce Support');
        mail.setSubject('New Case Created : ' + case.Id);
        try {
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });   
            emailSent = true;
            return null;
        }catch(Exception e) {
             emailSent = false;
             return null;
And here is my Template;
<messaging:emailTemplate subject="Christmas Card List" recipientType="User" relatedToType="AccountTag" rendered="true">
    <messaging:htmlEmailBody >
     <p> please work! </p>
   <messaging:attachment fileName="cardList.csv">
         <c:cardList />
The custom component cardList is:
<apex:component controller="ChristmasCardController" access="global">
    <apex:repeat var="taggedAccount" value="{!taggedAccountsInformation}" >
        {!taggedAccount.Name}, {!taggedAccount.BillingStreet}, {!taggedAccount.BillingCity}, {!taggedAccount.BillingPostalCode}, {!taggedAccount.BillingState}, {!taggedAccount.BillingCountry}
I know the custom component works, because I have tested it within a visual force page.
Please, Please can you help? Thank you very much
  • November 28, 2008
  • Like
  • 0