• Hobbele12354624
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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.setToAddresses(toAddresses);
        mail.setReplyTo('jbloggs@salesforce.com');
        mail.setSenderDisplayName('Salesforce Support');
        mail.setSubject('New Case Created : ' + case.Id);
        mail.setUseSignature(false);
        mail.setTemplateId('00X200000015XFL');
        try {
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });   
            emailSent = true;
            return null;
        }catch(Exception e) {
             System.debug(e.getMessage());
             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:htmlEmailBody>
   <messaging:attachment fileName="cardList.csv">
         <c:cardList />
   </messaging:attachment>
</messaging:emailTemplate>
 
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}
    </apex:repeat>
</apex:component>
 
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