I have requirement to bring child object field in email template.
I have created custom controller "quoteEmailTemplate" that uses a SOSL call to return a list of Cabinets , I have created custom component named "quoteEmailTemplate" that uses this controller then included the component to visual force template.
Below is my code -
Controller -
public class quoteEmailTemplate {
// public String recordId;
public Id recordId {get;set;}
public List<Theme_Conversion__c> quoteItemList{get;set;}
public quoteEmailTemplate(){
quoteItemList =new List<Theme_Conversion__c>();
quoteItemList = [SELECT id,Name,Sales_Toolkit__c,Cabinet__c,Cabinet__r.Name,Brand__c,Brand__r.Name, File_Number__c,Notes__c,Quantity__c
FROM Theme_Conversion__c WHERE Sales_Toolkit__c =: recordId];
System.debug('quoteLineitemList---'+quoteItemList);
}
public List<Theme_Conversion__c> getquoteLineitemLists ()
{
List<Theme_Conversion__c> quoteLineitemList;
quoteLineitemList = [SELECT id,Name,Sales_Toolkit__c,Cabinet__c,Cabinet__r.Name,Brand__c,Brand__r.Name, File_Number__c,Notes__c,Quantity__c
FROM Theme_Conversion__c WHERE Sales_Toolkit__c =: recordId];
System.debug('quoteLineitemList---'+quoteLineitemList);
return quoteLineitemList;
}
}
Visualforce Component -
<apex:component controller="quoteEmailTemplate" access="global">
<apex:attribute name="relatedToId" type="Id" description="Id of the Quote" assignTo="{!recordId}" />
<table border="2" cellspacing="5">
<p>Quote Worksheet Line Item Details : -</p>
<tr>
<td>Cabinet Name</td>
<td>Quantity</td>
</tr>
<apex:repeat value="{!quoteItemList}" var="quote">
<tr>
<td style="background-color:white;">{!quote.Cabinet__r.Name}</td>
<td style="background-color:white;">{!quote.Quantity__c}</td>
</tr>
</apex:repeat>
</table>
</apex:component>
Visualforce Email Template -
<messaging:emailTemplate recipientType="User"
relatedToType="Sales_Toolkit__c"
subject="{!relatedTo.Status__c} - {!relatedTo.Document_Number__c} - {!relatedTo.Account__r.Name}"
replyTo="[email protected]" >
<messaging:htmlEmailBody >
<html>
<head>
<style>
th, td {
font-size:10pt;
font-family:Arial;
}
th {
font-weight: bold;
background-color: gray;
}
</style>
</head>
<body>
<font face="arial" size="2">
<p> {!relatedTo.Owner.Name} has submitted an approval request on the following quote.</p><br/>
<p>
The details of this quote and any attachments can be found at this link:
<apex:outputlink value="{!LEFT($Api.Partner_Server_URL_270,FIND('.com',$Api.Partner_Server_URL_270)+4)+relatedTo.id}">
Click here</apex:outputlink>
</p>
<br/>
Requester: {!relatedTo.Owner.Name}<br/>
Quote Number:{!relatedTo.Name}<br/>
Opp Number:{!relatedTo.Opp_Num__c}<br/>
Quote Record Type :{!relatedTo.RecordType.Name}<br/>
Account: {!relatedTo.Account__r.Name}<br/>
Customer Tier: {!relatedTo.Account__r.Customer_Tier__c}<br/>
Close Date:
<apex:outputText value="{0,date,MM/dd/yyyy HH:MM a}">
<apex:param value="{!relatedTo.Close_Date__c}" />
</apex:outputText><br/>
Install Date:
<apex:outputText value="{0,date,MM/dd/yyyy HH:MM a}">
<apex:param value="{!relatedTo.Install_Date__c}" />
</apex:outputText><br/>
Notes: {!relatedTo.Notes__c}<br/>
Revenue Model: {!relatedTo.Payment_Terms__c}<br/>
<c:quoteWorksheetTemplate />
</font>
</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Attaching the email template Output, Cabinet and quantity belongs to cross object and Controller is not loading them, can someone help me on this?
relatedTo
parameter to the component. Change it to this;<c:quoteWorksheetTemplate relatedTo="{!relatedTo.Id}" />