+ Start a Discussion
Marianne KomeskiMarianne Komeski 

Aggregate Relationship is used in an unsupported complex expression

I am trying to pull attachments from a parent object onto the approval email alert (as links) when the child object is submitted for approval.  I am able to pull all the fields from the parent object onto the VF template; but for some reason attachments will not work and i receive the following error message:  Error: Aggregate Relationship is used in an unsupported complex expression containing 'OBJECTA__r.attachments'. 

Beginning of template:
<messaging:emailTemplate subject="CDR Approval Request - {!RelatedTo.PARENT__r.Account__r.Name}" recipientType="User" relatedToType="CHILD__c">
<messaging:htmlEmailBody >

Section pertaining to attachments:
<apex:repeat value="{!relatedTo.PARENT__r.Attachments}" var="a"> 
 <p><a href="https://CS15.salesforce.com/{!URLFOR($Action.Attachment.Download, a.name)}">{!a.Name}</a> ({!a.BodyLength} B)</p>

I believe referencing 'PARENT__r' is the problem, but I do not know how else to reference that the attachments need to pull from the parent object (not child as it will have none)?

Do I need to create a controller to pull the parent object attachments and then reference that controller in the email template??

Please help!
Yes, you should probably create an apex class and component to query and display what you need. Then include the component in the template.

<c:ComponentName relatedToId="{!relatedTo.Id}"/>