You need to sign in to do that
Don't have an account?
ahon
Email Template - Related Lists
How do I display two related lists of an object on an email template? For example, a related list with relevant related lists nested under each row. Does not have to invovled code.
Here is my code:
<messaging:emailTemplate subject=""
recipientType=""
replyTo=""
relatedToType="">
<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>Below are Components and Sub-Components</p>
<table border="0">
<tr>
<th>x</th>
<th>x</th>
<th>x</th>
<th>x</th>
<th>x</th>
<th>x</th>
</tr>
<apex:repeat var="component" value="{!relatedTo.SGI_Components__r}">
<apex:outputPanel layout="none" rendered="{!component.Component_Status__c != 'Open'}">
<tr>
<td>{!component.Name}</td>
<td>{!component.Part_Number__c}</td>
<td>{!component.Total_Part_Authorized__c}</td>
<td>{!component.Labor_Amount__c}</td>
<td>{!component.Total_Amount__c}</td>
<td>{!component.Component_Status__c}</td>
</tr>
<apex:variable var="subComponents" value="{!component.SGI_Claim_Subcomponent__r}" />
<apex:outputPanel layout="none" rendered="{!NOT(ISBLANK(subComponents))}">
<tr>
<td colspan="6">
<table>
<tr>
<th>Sub-Component Name</th>
<th>Sub-Component Part Number</th>
<th>Sub-Component Total Authorized</th>
<th>Sub-Component Status</th>
</tr>
<apex:repeat var="subComponent" value="{!subComponents}">
<tr>
<td>{!subComponent.Name}</td>
<td>{!subComponent.Part_Number__c}</td>
<td>{!subComponent.Total_Authorized_Amount__c}</td>
<td>{!subComponent.Subcomponent_Status__c}</td>
</tr>
</apex:repeat>
</table>
</td>
</tr>
</apex:outputPanel>
</apex:outputPanel>
</apex:repeat>
</table>
Here is my code:
<messaging:emailTemplate subject=""
recipientType=""
replyTo=""
relatedToType="">
<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>Below are Components and Sub-Components</p>
<table border="0">
<tr>
<th>x</th>
<th>x</th>
<th>x</th>
<th>x</th>
<th>x</th>
<th>x</th>
</tr>
<apex:repeat var="component" value="{!relatedTo.SGI_Components__r}">
<apex:outputPanel layout="none" rendered="{!component.Component_Status__c != 'Open'}">
<tr>
<td>{!component.Name}</td>
<td>{!component.Part_Number__c}</td>
<td>{!component.Total_Part_Authorized__c}</td>
<td>{!component.Labor_Amount__c}</td>
<td>{!component.Total_Amount__c}</td>
<td>{!component.Component_Status__c}</td>
</tr>
<apex:variable var="subComponents" value="{!component.SGI_Claim_Subcomponent__r}" />
<apex:outputPanel layout="none" rendered="{!NOT(ISBLANK(subComponents))}">
<tr>
<td colspan="6">
<table>
<tr>
<th>Sub-Component Name</th>
<th>Sub-Component Part Number</th>
<th>Sub-Component Total Authorized</th>
<th>Sub-Component Status</th>
</tr>
<apex:repeat var="subComponent" value="{!subComponents}">
<tr>
<td>{!subComponent.Name}</td>
<td>{!subComponent.Part_Number__c}</td>
<td>{!subComponent.Total_Authorized_Amount__c}</td>
<td>{!subComponent.Subcomponent_Status__c}</td>
</tr>
</apex:repeat>
</table>
</td>
</tr>
</apex:outputPanel>
</apex:outputPanel>
</apex:repeat>
</table>
Main Component #1
Sub #2
<messaging:emailTemplate subject="Claim Coversheet"
recipientType="Contact"
replyTo="aoneill@sgintl.com"
relatedToType="SGI_Claim__c">
<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>Below are Claim # {!relatedto.Claim_Id__c} Components and Sub-Components</p>
<table border="0">
<tr>
<th>Name</th>
<th>Part Number</th>
<th>Total Authorized</th>
<th>Labor Total</th>
<th>Total Amount</th>
<th>Component Status</th>
</tr>
<apex:repeat var="component" value="{!relatedTo.SGI_Components__r}">
<apex:outputPanel layout="none" rendered="{!component.Component_Status__c != 'Open'}">
<tr>
<td>{!component.Name}</td>
<td>{!component.Part_Number__c}</td>
<td>{!component.Total_Part_Authorized__c}</td>
<td>{!component.Labor_Amount__c}</td>
<td>{!component.Total_Amount__c}</td>
<td>{!component.Component_Status__c}</td>
</tr>
<apex:variable var="subComponents" value="{!component.SGI_Claim_Subcomponent__r}" />
<apex:outputPanel layout="none" >
<tr>
<td colspan="6">
<table>
<tr>
<th>Sub-Component Name</th>
<th>Part Number</th>
<th>Total Authorized</th>
<th>Status</th>
</tr>
<apex:repeat var="subComponent" value="{!subComponents}">
<tr>
<td>{!subComponent.Name}</td>
<td>{!subComponent.Part_Number__c}</td>
<td>{!subComponent.Total_Authorized_Amount__c}</td>
<td>{!subComponent.Subcomponent_Status__c}</td>
</tr>
</apex:repeat>
</table>
</td>
</tr>
</apex:outputPanel>
</apex:outputPanel>
</apex:repeat>
</table>
<br/>
<br/>
<p>
Sincerely,<br/></p>
x<br/>
Return Email: x<br/>
<br/>
<font color="red">
x
</font>
<br/>
<br/>
<font color="red">
v6.0
</font>
<br/>
</font>
</body>
</html>
All Answers
To display two related lists of an object on an email template with nested related lists, you can use Visualforce components such as <apex:repeat> and <apex:outputPanel> to iterate over the related lists and conditionally render the nested related lists
Please try with the below code:
Please ensure that you have replaced the placeholder "x" with the appropriate column headers for your related lists.
If this helps , please mark this as Best Answer.
Thank you.
Main Component #1
Sub #2
<messaging:emailTemplate subject="Claim Coversheet"
recipientType="Contact"
replyTo="aoneill@sgintl.com"
relatedToType="SGI_Claim__c">
<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>Below are Claim # {!relatedto.Claim_Id__c} Components and Sub-Components</p>
<table border="0">
<tr>
<th>Name</th>
<th>Part Number</th>
<th>Total Authorized</th>
<th>Labor Total</th>
<th>Total Amount</th>
<th>Component Status</th>
</tr>
<apex:repeat var="component" value="{!relatedTo.SGI_Components__r}">
<apex:outputPanel layout="none" rendered="{!component.Component_Status__c != 'Open'}">
<tr>
<td>{!component.Name}</td>
<td>{!component.Part_Number__c}</td>
<td>{!component.Total_Part_Authorized__c}</td>
<td>{!component.Labor_Amount__c}</td>
<td>{!component.Total_Amount__c}</td>
<td>{!component.Component_Status__c}</td>
</tr>
<apex:variable var="subComponents" value="{!component.SGI_Claim_Subcomponent__r}" />
<apex:outputPanel layout="none" >
<tr>
<td colspan="6">
<table>
<tr>
<th>Sub-Component Name</th>
<th>Part Number</th>
<th>Total Authorized</th>
<th>Status</th>
</tr>
<apex:repeat var="subComponent" value="{!subComponents}">
<tr>
<td>{!subComponent.Name}</td>
<td>{!subComponent.Part_Number__c}</td>
<td>{!subComponent.Total_Authorized_Amount__c}</td>
<td>{!subComponent.Subcomponent_Status__c}</td>
</tr>
</apex:repeat>
</table>
</td>
</tr>
</apex:outputPanel>
</apex:outputPanel>
</apex:repeat>
</table>
<br/>
<br/>
<p>
Sincerely,<br/></p>
x<br/>
Return Email: x<br/>
<br/>
<font color="red">
x
</font>
<br/>
<br/>
<font color="red">
v6.0
</font>
<br/>
</font>
</body>
</html>