You need to sign in to do that
Don't have an account?

Cannot Send Email when including VFEmail Template
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'};
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.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;
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;
}
}
}
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>
<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>
<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
All Answers
Also, I should mention that even when I create a blank VF template
and add the associated ID to the setTemplateID it still will not work.
It will work if I remove the setTemplateID and replace it with mail.setPlainTextBody('This is the text body: ');
Thanks
If i choose the Template, the Merge Fields are not filled.
relatedToType="Lead" in the Template
and
mail.setTargetObjectId(getLeadId()); in the Code.
It works without filling the merge fields with the Lead details.
Can anyone help us? It is very important for me!
Message Edited by Hobbele on 12-11-2008 05:22 AM
Please, its very important for me!