1

I am having lookup relationship between case and .Case_PO custom object. I am using site to create new case record with .Case_PO child record also. After creating a new case record with related list records I email this to Case Contact. For this I am using vf email template it works fine and email is going to the case contact. But in the email I am not getting the information of related list record, PO table is showing empty for that case but in the org I am having PO for that case. I am sending email to Case contact using workflow rule.Can any one tell how to all the realted list record when creating a case and email this information . Here I have attached vf email template for this.

VF Email Template:

<messaging:emailTemplate subject="DC Receiving Query Submitted – Case Number:  {!relatedTo.CaseNumber} DC: {!relatedTo.Distribution_Centre__r.DC_Number__c} - Vendor - {!relatedto.Vendor_Number__r.Vendor_Number__c} {!relatedto.Vendor_Number__r.Name} " recipientType="Contact" relatedToType="Case">

<messaging:htmlEmailBody >
<html>
      <body>
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 0;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #CCCCCC; border-width: 0}
          TR {border: solid #CCCCCC; border-width: 0}
        </STYLE>
        <font face="arial" size="2">
          <!--<p>Hi {!recipient.name},</p>-->

          <p>Hi {!relatedTo.DC_Contact_Name__r.Name},</p>
          <p>Please see below confirming details of your DC receiving query raised {!relatedTo.Created_DateTime__c}.For your reference, the case number for this query is  {!relatedTo.CaseNumber} .</p>
    <table cellspacing="0" cellpadding="0" border="0" >
                    <tr>
                        <td align="left"><p style="font-family:Helvetica Neue,arial;font-size:12px;color:#333333;line-height:17px;padding-left:2px;">
                            <b>DC:</b>&nbsp;&nbsp; {!relatedTo.Distribution_Centre__r.DC_Number__c}<br></br>
                            <b>Vendor Number:</b>&nbsp;&nbsp; {!relatedto.Vendor_Number__r.Vendor_Number__c}<br></br>
                             <b>Vendor Name:</b>&nbsp;&nbsp; {!relatedto.Vendor_Number__r.Name}<br></br>
                            <b>Query Type  :</b>&nbsp;&nbsp; <apex:outputField value="{!relatedto.Type}"/><br></br>
                            </p>
                        </td>
                    </tr>
       </table>
<table colunm = "6" border = "5">
            <tr > 

               <th>PO Number(s)</th>
               <th> Buyer Name</th>
               <th> Event Number </th>
               <th> Container Number </th>
               <th> Number Pallets / Cartons </th>
               <th> Booking Date / Time</th>


            </tr>
            <apex:repeat var="cx" value="{!relatedTo.Case_PO__r}">
              <tr>                
                <td>{!cx.PO__r.Name}</td>
                <td>{!cx.PO__r.Department_Team__r.Name}</td>
                <td>{!cx.PO__r.Event_Number__c}</td>
                <td>{!cx.PO__r.Container_Number__c}</td>

                <td>{!cx.PO__r.Number_Pallets_Cartons__c}</td>
                <td>{!cx.PO__r.Booking_Date_Time__c}</td>
              </tr>
            </apex:repeat>
            </table>                    



            <br/>
            <br/>
            You will receive a further updates as your request is reviewed.<br/>  
            <br/> 
            <br/>         
              <b> Kind Regards,</b><br/>
               Capacity and Scheduling Team,<br/> 
               Big W,<br/> 
               Australia.<br/>            



    </font>
      </body>
    </html>
</messaging:htmlEmailBody>

<messaging:plainTextEmailBody >
 Hi {!relatedTo.DC_Contact_Name__r.Name},

   Please see below confirming details of your DC receiving query raised {!relatedTo.CreatedDate}.For your reference, the case number for this query is  {!relatedTo.CaseNumber}
   [ PO Number(s) ] -[ Buyer Name ]- [ Event Number] - [ Container Number] -[ Number Pallets / Cartons] - [ Booking Date / Time ]

    <apex:repeat var="cx" value="{!relatedTo.Big_W_Case_PO__r}">
     [ {!cx.PO__r.Name} ]-[{!cx.PO__r.Department_Team__r.Name}] - [{!cx.PO__r.Event_Number__c} ] - [ {!cx.PO__r.Container_Number__c} ] - [{!cx.PO__r.Number_Pallets_Cartons__c}] - [{!cx.PO__r.Booking_Date_Time__c}]
    </apex:repeat>




</messaging:plainTextEmailBody>
</messaging:emailTemplate>
2

To elaborate a bit more on Stuart's answer:

  1. The VF template's relatedTo if used in a workflow email alert will invoke the standardController for the triggered object - in your example: 'Case'. The standard controller for Case will not have access in memory to any of Case's related lists.
  2. The VF template's relatedTo if used in an Apex SingleEmailMessage has access to whatever the Apex code retrieves in the SOQL call - including any related lists via relationship queries - e.g. Case myCase = [select id, (select id, ... from case_po__r) from Case where ...]; and associates the resulting Sobject instance in the myEmail.setWhatId(myCase.id) method. That is, setWhatId(..) gives relatedTo its merge fields.
  3. For VF custom components with their own controller, the component can be passed whatever it needs to locate the related list in the component's controller as shown in Stuart's example. The component would not reference relatedTo.
1

The only way I have done it in the past is to create a component that generates the table and embed the component in the VF email template.

ie. In the email template I would have

...email message...

 <c:FECTable contactId="{!relatedTo.Dealer__c}"
             recipientType="Dealer"
             reminderDays="{!IF(ISNULL(relatedTo.Reminder_Days__c))}"/>

...email message...

The FECTable component would have a controller that would collect all the related records required, do any complex processing and store the results in an array that could be easily displayed in a table. The component would display the array as a table much like in your example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.