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

VF email template on Opportunity, can I display contacts from related account?
Hi, I have a VF email template on the Opportunity object. I've been asked to include contact information from the related account but I can't work out how to get this into the template.
This is the code:
messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
replyTo="xxx@xxx.org" >
<messaging:htmlEmailBody >
<html>
<body>
<apex:image id="Email_Header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=xxxxx&oid=xxxxx"
height="130" width="600"/>
<STYLE type="text/css">
TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0; text-align: center }
TD {font-size: 14px; font-face: arial }
</STYLE>
<font face="arial" size="2">
<br/>
<br/>
<p/> Dear
<apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>
</apex:repeat>,
<br/>
<br/>
{!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
<br/>
Our records show the information below about your company:
<br/>
<br/>
<td><b>• </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
<br/>
<td><b>• </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>
<p/> <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
<tr>
<td><b>• </b> Membership type {!opp.PriceBookEntry.name}.</td> <br/>
</tr>
</apex:repeat>
<br/>
<p/> <apex:repeat var="acc" value="{!relatedTo.Account}">
<tr>
<td><b>• </b> Main Contact "{!relatedto.acc.Contacts}".</td> <br/>
</tr>
</apex:repeat>
The part in italics is what I have added to try and include the contact related list but I get the error 'Invalid field acc for SObject Opportunity'.
I'm not good on code; is there a simple way to bring in a related list from a related object?
Any help is much appreciated!
Thanks.
This is the code:
messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
replyTo="xxx@xxx.org" >
<messaging:htmlEmailBody >
<html>
<body>
<apex:image id="Email_Header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=xxxxx&oid=xxxxx"
height="130" width="600"/>
<STYLE type="text/css">
TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0; text-align: center }
TD {font-size: 14px; font-face: arial }
</STYLE>
<font face="arial" size="2">
<br/>
<br/>
<p/> Dear
<apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>
</apex:repeat>,
<br/>
<br/>
{!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
<br/>
Our records show the information below about your company:
<br/>
<br/>
<td><b>• </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
<br/>
<td><b>• </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>
<p/> <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
<tr>
<td><b>• </b> Membership type {!opp.PriceBookEntry.name}.</td> <br/>
</tr>
</apex:repeat>
<br/>
<p/> <apex:repeat var="acc" value="{!relatedTo.Account}">
<tr>
<td><b>• </b> Main Contact "{!relatedto.acc.Contacts}".</td> <br/>
</tr>
</apex:repeat>
The part in italics is what I have added to try and include the contact related list but I get the error 'Invalid field acc for SObject Opportunity'.
I'm not good on code; is there a simple way to bring in a related list from a related object?
Any help is much appreciated!
Thanks.
Try this
<p/> Dear
<apex:repeat value="{!RelatedTo.Account.Contacts}" var="contacts">
</apex:repeat >
I have also tried this:
<apex:repeat var="acc" value="{!relatedTo.Account}">
<tr>
<td><b>• </b> Main contact {!relatedto.Account.Contacts}.</td> <br/>
</tr>
</apex:repeat>
But get the following error message: Aggregate Relationship is used in an unsupported complex expression containing 'Account.contacts'
Many thanks.