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
JimInSRQJimInSRQ 

Reference Child custom object from Parent custom using apex:repeat in VF email template

I have two custom objects, RMA (Parent) and RMA Device (Child).  I'm trying to use apex:repeat in a VF email template to list the all Devices in RMA Device related to RMA.  I receive "Error: Invalid field RMA_Device__c for SObject RMA__c", when trying to save the template.
 
RMA_Device__c is the API name for the child object.

Below is the entire code set for the template
 
<messaging:emailTemplate subject="Return Material Authorization" recipientType="Contact" relatedToType="RMA__c">

<messaging:htmlEmailBody >
<html>
<div style='width:800px;margin:auto;' >
<body>
<p>This is a list of all RMA Devices related to: {!relatedTo.name}</p>
    <table border="0" >
        <tr>
            <th style="width:175px" align="left">RMA Dev ID</th>
            <th style="width:175px" align="left">Part Number</th>
            <th style="width:175px" align="left">Serial</th>
            <th style="width:275px" align="left">RMA Category</th>
        </tr>
        
        <apex:repeat var="cx" value="{!relatedTo.RMA_Device__c}">
        
        <tr>
            <td><a href = "https://***yourInstance***.salesforce.com/{!cx.id}">{!cx.Name}
            </a></td>
            <td>{!cx.Part_Number__c}</td>
            <td>{!cx.Contact.Serial__c}</td>
            <td>{!cx.RMA_Category__c}</td>
        </tr>
        
        </apex:repeat>
    </table>
    <p/>
    <center>
    <apex:outputLink value="http://www.salesforce.com">
    For more detailed information login to Salesforce.com
    </apex:outputLink>
    </center>
</body>
</div>
</html>
</messaging:htmlEmailBody>


<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>


 
Roshni RahulRoshni Rahul
Hi Jim,

The problem you are facing is that you are not referencing the child relationship properly. Salesforce generates a child relationship name that you need to reference in the page. For Account to Contact it is Contacts. But they are standard, trying the same for Child will not work. Salesforce asks for a relationship name when creating the lookup relationship or master detail relationship. If a name is not provided, a unique Id is generated. You can go and edit the relationship name later on. You can also check out the relationship name in Apex Explorer or Salesforce Schema browser in Eclipse. Go to the parent Object, drill down to the child relationships and you will find the relationship name.
 
Lets say, Custom_Object_1__c, I have a child object named, Custom_Object_2__c. The way to reference it is then {!Custom_Object_1__c.Custom_Object_2__r}

Regards
Roshni
JimInSRQJimInSRQ

Roshni,  Thanks for the response.  I did find that yesterday after more research.  

<apex:repeat var="cx" value="{!relatedTo.RMA_Devices__r}">