0

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?

2
  • You're not passing in the relatedTo parameter to the component. Change it to this; <c:quoteWorksheetTemplate relatedTo="{!relatedTo.Id}" /> Nov 14, 2021 at 18:10
  • @rael_kid - that is the answer; you should post it
    – cropredy
    Nov 15, 2021 at 1:09

1 Answer 1

0

You're not passing in the relatedTo parameter to the component. Change it to this; <c:quoteWorksheetTemplate relatedToId="{!relatedTo.Id}" />

For safety, you should mark the attribute in the component as required, like so;

<apex:attribute name="relatedToId" required="true" type="Id" description="Id of the Quote" assignTo="{!recordId}" />

If you mark it as required, the template should not save in its current form, because it's missing the parameter.

Please find the attach image .enter image description here

3
  • @real_Kid Its not letting me mark as required="true" and when I am passing relatedTo parameter to the component ( <c:quoteWorksheetTemplate relatedTo="{!relatedTo.Id}" />) its giving me error unsupoorted attribute Error: Unsupported attribute relatedto in <c:quoteWorksheetTemplate> in Capex_Template_For_Approver at line 49 column 67 Nov 15, 2021 at 20:28
  • You should use relatedToId="{!relatedTo.Id}", I've updated my answer. Nov 16, 2021 at 13:45
  • Also, you should not modify an answer to provide feedback; just use a comment and move the image you posted from my answer to the question. Nov 16, 2021 at 13:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .