You need to sign in to do that
Don't have an account?
Related list in VisualForce Email template - custom objects possible?
Hi All -
I am new, so please forgive my green - but I am having a perplexing problem in generating a Visual Force email template showing related lists for a custom object.
I CAN get a list of Cases related to an Account with no problem, but when I put in a custom object (Child Relationship Name "Suppliers") which is also (Master-Detail) related to Account I get the following error: Error: Invalid field Suppliers for SObject Account
I have tried everything I can think of - using API name instead, appending "__c" to the end, but it seems that i can't make any lists at all with custom objects in this code.
Is there a restriction within this type of code that allows only lists with standard objects or is there something I'm missing?
Any help would be greatly appreciated. I am not good enough to make a custom Apex controller yet and a little under the gun to kluge something together.
Thanks much,
Lex
Below is relevant code:
<messaging:emailTemplate recipientType="Contact"
relatedToType="Account"
subject="Supplier report for Account: {!relatedTo.name}"
replyTo="support@acme.com" >
<messaging:htmlEmailBody >
<html>
<body>
<STYLE type="text/css">
TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1; text-align: center }
TD {font-size: 11px; font-face: verdana }
TABLE {border: solid #CCCCCC; border-width: 1}
TR {border: solid #CCCCCC; border-width: 1}
</STYLE>
<font face="arial" size="2">
<p>Dear {!recipient.name},</p>
<p>Below is a list of supplier records related to the account: {!relatedTo.name}.</p>
<table border="0" >
<tr >
<th>Action</th><th>Product</th><th>Status</th><th>Creator Email</th><th>BL date</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Suppliers}">
<tr>
<td><a href="https://na1.salesforce.com/{!cx.id}">View</a> |
<a href="https://na1.salesforce.com/{!cx.id}/e">Edit</a></td>
(...snip...)
I think you want the relationship field, so relatedTo.suppliers__r
All Answers
I think you want the relationship field, so relatedTo.suppliers__r
Bless you my saviour! ;)
Thank you so much for responding, you have just solved a problem that has been holding me up for three days!!!
Thank you! Thank you! Thank you!
Alex
This seems to only display the one related record. How do I display all of the records related to an object within a related list.
Visual Force Email Templates with Related List only works in Preview Mode. When the Email Alert is triggered using a workflow , the Email contains no data.
I have a custom object called Project__c (Master-Detail with Account) and I tried 'projects__r' and 'project__r' but I still get this error:
Error: Invalid field project__r for SObject Account
<messaging:emailTemplate subject="Quote Information" recipientType="User" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf">
<head>
<style>
@page {
size: auto; /* auto is the initial value */
margin-top: 0.0%;
margin-left: 4mm;
margin-right: 4mm;
margin-bottom: 4mm;
}
td{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
.tds{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
td.normal{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
td.nbold{
font-family:Arial,Helvetica,sans-serif;
font-weight:bold;
font-size:15px;
}
</style>
</head>
The Discount on the Quote exceeds the maximums alloted and hence requires approval.
Below is the Opportunity information:
Opportunity Name : {!relatedTo.Name}
Opportunity Account : {!relatedTo.Account}
Close Date: {!relatedTo.CloseDate}
Stage: {!relatedTo.StageName}
Amount: {!relatedTo.Amount}
Link: {!relatedTo.Link}
<tr>
<td width = "14%"><b>Quote Number</b></td>
<td width = "10%"><b>Quantity</b></td>
<td width = "44%"><b>Expiration Date</b></td>
<td width = "44%"><b>Discount</b></td>
</tr>
<apex:repeat value="{!relatedTo.Quotes__r}" var="line">
<tr>
<td>{!line.QuoteNumber}"/></td>
<td>{!line.Name}"/></td>
<td>{!line.ExpirationDate}"/></td>
</tr>
</apex:repeat>
<tr><td> </td></tr>
<tr><td> </td></tr>
</messaging:attachment>
</messaging:emailTemplate>