We are trying to add attachments to an email template using a component. The code in the email template is:
<messaging:emailTemplate subject="My Subject" recipientType="User" relatedToType="My_Custom_Object__c">
<messaging:htmlEmailBody >
All,
blah, blah, blah
<apex:outputText value="If you have any questions, please email "/>
<apex:outputLink value="mailto:[email protected]"/>[email protected]
</messaging:htmlEmailBody>
<messaging:plainTextEmailBody >
All,
blah, blah, blah
</messaging:plainTextEmailBody>
<c:IncludeAttachments parentId="{!relatedTo.Id}" include="MostRecent"/>
</messaging:emailTemplate>
The component IncludeAttachments code is:
<apex:component controller="IncludeAttachmentsController" access="global">
<apex:attribute name="parentId"
description="Parent Id"
assignTo="{!parentObjectId}"
type="Id" />
<apex:attribute name="include"
description="Include parameter"
assignTo="{!includeAttachments}"
type="String" />
<apex:repeat value="{!attachments}" var="attachment">
<messaging:attachment renderAs="{!attachment.contentType}" fileName="{!attachment.name}">{!attachment.body}</messaging:attachment>
</apex:repeat>
</apex:component>
The IncludeAttachmentsController code is:
global class IncludeAttachmentsController {
/* Variables and Constants */
global Id parentObjectId { get; set; }
global String includeAttachments { get; set; }
private static final String INCLUDE_ALL = 'All';
private static final String INCLUDE_MOST_RECENT = 'MostRecent';
public List<Attachment> attachments {
get {
if (INCLUDE_ALL.equalsIgnoreCase(includeAttachments)) {
return [select
name
, contentType
, body
from Attachment
where parentId = :this.parentObjectId];
} else { // include most recent
return [select
name
, contentType
, body
from Attachment
where parentId = :this.parentObjectId
order by CreatedDate desc
limit 1];
}
}
set;
}
Two problems: The email link does not show up as a link, just text.
We get the following error:
Error: Invalid child of messaging:emailTemplate. Only messaging components are allowed as children of messaging:emailTemplate.
Can anyone help us resolve these two problems?