function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RailCIORailCIO 

Master Detail to Master RelatedTo Naming within APEX Email Communication

So the problem here is how to move from a Master File to a junction file over to the other Master file using the apex relatedto command within a Visualforce Email template.

We lease fleets of cars and we are developing a process to provide detail from both the standard Contract object,  a custom built Car object and a junction object named Contract Cars. 

Using a Visualforce email communicaton template related to the Contract object, i am able to pull in all values from related tables.  I am having difficulty in the naming of the junction table as a bridge over to custom Car object.   The link from the junction object Contract Car to the custom Car object is name Car__C.  In this example it is defiend as Car__R.   Below is a small sample of the code. 


 <messaging:emailTemplate subject="Approval" recipientType="User" relatedToType="Contract">

  <messaging:htmlEmailBody >
  <html>
     <body>
       <font face="arial" size="2">
       <p>Contract Rates </p>
        <table border="0" >
          <tr >
        <th>Contract Cars</th>
        </tr>
       <apex:repeat var="cc" value="{!relatedTo.Contract_Cars__r}">
       <tr>
          <td>{!cc.name}</td>
          <td>{!cc.car__r.car_id}</td>
        </tr>
        </apex:repeat>                
      </table>
   </font>
   </body>
   </html>
  </messaging:htmlEmailBody>

Shashikant SharmaShashikant Sharma
You could create visualforce component and use it in VF Email template to show these values. You could pass attribute values and fetch all information in the component controller class.