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
Christophe LucchiniChristophe Lucchini 

Visualforce template related list

Hi everyone,

I'm trying to create my first mail Template visualforce page , and in this page i have to put a related list associated on the Objects "contracts" , the relate list is called "Machines under Warranty" (ass you can see in pic):
User-added image

The primary objective is to create an email template wich contain the Machine in Warranty according to the actual contract of the client.

Here is my visualforce templace (sorry if its really bad because i don't have the time to train on this and i have an urgent asking from my Customer service):

<messaging:emailTemplate subject="PellencST Warranty test" recipientType="Contact" relatedToType="Contract">
<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>Bonjour,</p>
<p>Nous vous informons que la garantie de vos trieurs optique PellencST arrive à échéance.</p>
 
<p>En effet votre contrat de garantie a débuté le {!relatedTo.StartDate} et se termine le {!relatedTo.EndDate} pour les machines suivantes:</p>
 
 
 
<p>Vous trouverez ci-dessous un tableau récapitulatif des différentes options de contrats de services auxquelles vous pouvez souscrire afin de garder un service adapté pour un fonctionnement optimum de vos équipements:</p>
 
<table border="0" >
    <tr >
        <th>Machine Name</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Machine__c}">
        <tr>
            <td>{!cx.Machine_Name__c}</td>
        </tr>
    </apex:repeat>                
</table>
<p />
 
<p>Désormais votre dossier est suivi par notre Service Client ainsi pour tous conseils dans ces démarches vous pouvez contacter notre service au 04.90.09.47.94 ou par mail au sav@pellenct.com.</p>
 
 
<p>Le service client PellencST</p>
 
<p>sav@pellencst.com</p>
<p>+334 90 09 47 94</p>
<p>PELLENC ST</p>
 
<p>Pellenc ST | 125, rue François Gernelle | 84120 Pertuis | France | pellencst.com | +33 4 90 09 47 94</p>
 
 
<p>This email transmission is confidential and intended solely for the person or organization to who it is addressed. If you are not the intended recipient, you must not take any action in reliance of it.</p>
<p>Ce message et les pièces jointes sont confidentiels et établis à l’intention exclusive de ses destinataires. Toute utilisation de ce message non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse.</p>
            </font>
        </body>
    </html>
</messaging:htmlEmailBody > 
 
</messaging:emailTemplate>

The thing is i got a problem with this part i think:

<table border="0" >
    <tr >
        <th>Machine Name</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Machine__c}">
        <tr>
            <td>{!cx.Machine_Name__c}</td>
        </tr>
    </apex:repeat>                
</table>
<p />

Salesforce keep repeating me "Error: Unknown property 'String.Machine_Name__c'

Can someone help me with this, or maybe with the full template as i think, i have made many mistake.

Thanks !!
Best Answer chosen by Christophe Lucchini
Christophe LucchiniChristophe Lucchini
That's ok i found my answer !

I just had to put :

<table border="0" >
    <tr >
        <th>Machine Name serial Number</th>
        <th>Machine Name</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Machines__r}">
        <tr>
            <td>{!cx.Name}</td>
            <td>{!cx.Machine_Name__c}</td>
        </tr>
    </apex:repeat>                 
</table>
<p />

Machine__r was a différent related list than Machines__r

Thanks for the help !!!

All Answers

Aman MalikAman Malik
Hi,
Try to update
<apex:repeat var="cx" value="{!relatedTo.Machine__c}">
with
<apex:repeat var="cx" value="{!relatedTo.Machine__r}">

Hope this will help.

Thanks,
Aman
Christophe LucchiniChristophe Lucchini
Hi its ok now i just put like you said:

<table border="0" >
    <tr >
        <th>Machine Name serial Number</th>
        <th>Machine Name</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Machine__r}">
        <tr>
            <td>{!cx.Name}</td>
            <td>{!cx.Machine_Name__c}</td>
        </tr>
    </apex:repeat>                 
</table>
<p />

No more error, but when i try the template it just print the name:

th>Machine Name serial Number</th>
        <th>Machine Name</th>

But nothing in the table, as you can see:

User-added image
i don't know why he doesn't get the relate list from the contract ?

Can you help me please ?
Christophe LucchiniChristophe Lucchini
That's ok i found my answer !

I just had to put :

<table border="0" >
    <tr >
        <th>Machine Name serial Number</th>
        <th>Machine Name</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Machines__r}">
        <tr>
            <td>{!cx.Name}</td>
            <td>{!cx.Machine_Name__c}</td>
        </tr>
    </apex:repeat>                 
</table>
<p />

Machine__r was a différent related list than Machines__r

Thanks for the help !!!
This was selected as the best answer
EGA FuturaEGA Futura
https://medium.com/@cynthiabellmcgillis/todays-the-day-write-your-first-visualforce-email-template-fbbdeec2592c