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
mhamberg1mhamberg1 

email with custom object related list

I'm trying to send a Visualforce email template with custom object information that also lists out some child items. It's a pretty simple idea, but I'm getting a compile error because it doesn't like my child object reference. Can anyone help me correct this? I have bolded the problem line.

 

 

<messaging:emailTemplate subject="Changeover Order Form APPROVED"
recipientType="User" relatedToType="Changeover_Order_Form__c">
<messaging:plainTextEmailBody >

Details:
Account: {!relatedTo.Account__c}

Ingoing Order Amount: {!relatedTo.Ingoing_Order_Amount__c}
Package: {!relatedTo.Package_Options__c}
Gift Card Level: {!relatedTo.Gift_Card_Level__c}
Gift Card dollars used: {!relatedTo.Total_Gift_Card_dollars_used__c}

GIFT CARD SELECTION:
<apex:repeat var="gx" value="{!relatedTo.Gift_Card_Selection}">
Vendor: {!gx.Vendor_Card__c} ] - # of Cards: {!gx.of_Cards__c} ]
</apex:repeat>

View the record: http://www.salesforce.com/{!relatedTo.Id}

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

 

I made sure that the Child Relationship Name field was filled in with "Gift_Card_Selection."

Am I missing something else?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Try appending the __r syntax to this line:

 

 

<apex:repeat var="gx" value="{!relatedTo.Gift_Card_Selection__r}">

 

 Since you already clarified that you have properly set the Child Relationship Name to "Gift_Card_Selection", just append the __r to specify the relationship (just like __c specifies the custom field).

 

 

 

All Answers

aalbertaalbert

Try appending the __r syntax to this line:

 

 

<apex:repeat var="gx" value="{!relatedTo.Gift_Card_Selection__r}">

 

 Since you already clarified that you have properly set the Child Relationship Name to "Gift_Card_Selection", just append the __r to specify the relationship (just like __c specifies the custom field).

 

 

 

This was selected as the best answer
mhamberg1mhamberg1
Thanks! That was the trick.
elpaso750elpaso750

Hi there,

 

    I'm having the same issue and a similar situation.

 

 

I created a custom object with a master-detail relation to 'Contacts' This should keep track of all different groups a Contact joins.

 

Now I want to be able to send an email to the Contact listing the name of the groups joined.

 

I have :

 

 <messaging:emailTemplate subject="Your account's Mailing Lists" recipientType="Contact" relatedToType="Mailing_Lists__c">
<messaging:plainTextEmailBody >

SELECTION:
<apex:repeat var="gx" value="{!relatedTo.M_Lists__r}">
Title: {!gx.Mailing_List_Title__c} ] - Status : {!gx.Suspend_to__c} ]
</apex:repeat>

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

 

and made sure the  Child Relationship Name   is   M_Lists.  I did try with and without the __r but in both cases I getthe following error :

 

 Error: Invalid field M_Lists__r for SObject Mailing_Lists__c

 

Anybody can help if I'm missing something. This looks exactly the same as Mhamberg1 example but it works for him.

 

thanks

Alex

mhamberg1mhamberg1
Hi Alex, I'm not sure how much this helps, but just to reiterate my working version. These are the components that I have:

1. I have a VF email template (make sure you're not using a regular template).
2. My apex repeat section looks like:

<apex:repeat var="gx" value="{!relatedTo.Gift_Card_Selection__r}"> Vendor: {!gx.Vendor_Card__c} - # of Cards: {!gx.of_Cards__c} </apex:repeat>

 

3. Then on my custom object in the Lookup field that goes from my child object to its parent (I couldn't use a master detail because of the whole chaining constriction) I have this: Child Relationship Name Gift_Card_Selection

 

Hope that helps, make sure you don't have a typo somewhere,

Mike

elpaso750elpaso750

Hi Mike,

 

 Thanks so much for your hint.

 

 I've amended the relation from master-detail to Look-up field but no luck.

For the Templateyes I created a new one and selected VF.

 

Do I need creating any page or else with VF first ?

 

Thanks

Alex

mhamberg1mhamberg1

 

You don't need to create a page or anything else first. You also shouldn't need to make it a lookup relationship (mine just happens to be that).

 

 I'm not sure what else to tell you. I would double-check that your child relationship is named right and you don't have any typos. Also I see that you have right brackets in your text and I'm not sure why those are there (]).

 

The other place you can go for information is to read the manual on VF emails (which you've probably already done). 

 

Also I am using VF v15 and not 17 since I created this a year ago. I'm not sure if that makes a difference.

elpaso750elpaso750

Hi Mike,

 

 thanks for the hint.

 

 I realized I made a mistake for the  relatedToType string  (was using the child object rather than the father)

 

now I get no errors, but I also do not get any record from the related list......... :-(

 

I'll check again

 

thanks

Alex

elpaso750elpaso750

Hi Mike,

 

sorted thanks to the SF support team

 

see ya

 

Alex

mhamberg1mhamberg1

Can you post what the final fix was?

 

Thanks

elpaso750elpaso750

Hi Mike,

 

Sorry I did not see your message. In the meantime moving on with other stuff in VisualForce. Trying to understand  how I can see apex pages in Eclipse. The idea is to just copy/paste all the stuff I did create and test in the sandbox. Still trying to get out of a puddle :-))

 

this the amended code

 

Before it was :
... value="{!relatedTo.M_Lists__r}">

Amended to:
<apex:repeat var="gx" value="{!recipient.M_Lists__r}">

It is not possible to use ' Contact ' as an object  for a  'relatedToType'.
 

Alex

 

JMPlayer22JMPlayer22

I'm having a similar issue to the two above...I've read through the solutions to both and neither one is working for me.

 

I have a Custom object called "SFDC_520_Quote__c" and a related custom object called "Project_Piece__c" (the parent being "SFDC_520_Quote__c").  I'm trying to pull information from the child (Project_Piece__c) using an email template related to the parent (SFDC_520_Quote__c). Here's the code I have: 

<messaging:emailTemplate subject="TEST" recipientType="Contact" relatedToType="SFDC_520_Quote__c"> <messaging:htmlEmailBody > <table border="0" width="100%" id="table4"> <tr> <td width="30%" bgcolor="#C0C0C0"><font face="Arial">Product</font></td> <td width="40%" bgcolor="#C0C0C0"><font face="Arial">Description</font></td> <td bgcolor="#C0C0C0"><font face="Arial">Quantity</font></td> <td bgcolor="#C0C0C0"><font face="Arial">List Price</font></td> <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td> </tr> <tr> <apex:repeat value="{!relatedTo.Project_Piece__r}" var="line"> <tr> <td>{!line.name}</td> <!-- <td>{!line.ActualDescription__c}</td> <td><center>{!line.Quantity}</center></td> <td align="right"><apex:OutputField value="{!line.VS_List_Price__c}"/></td> <td align="right"><apex:OutputField value="{!line.VS_Total_Price__c}"/></td>--> </tr> </apex:repeat> </tr> </table> </messaging:htmlEmailBody> </messaging:emailTemplate>

 and here's the error:

 Error: Invalid field Project_Piece__r for SObject SFDC_520_Quote__c

 

 

JMPlayer22JMPlayer22
Nevermind...I figured out what the problem was.  I've been trying to use the API name of the child field instead of the child relationship name of the parent field on the child object (the name of the object had been changed from what it was upon creation of the object...originally it was called "Issues").
SwayampatiSwayampati

Hi folk,

 

Hopefully you smart guys can help me out here. I have similar problem like you. I am trying to send an email from custom object with the related list. My custom object is 'Sample Tracking'

I created an email button with the following.

 

location.replace('/email/author/emailauthor.jsp?retURL=/{!Sample_Tracking__c.Id}&rtype=003&p2_lkid={!  Sample_Tracking__c.Recipient_ContactId__c }&template_id=00XJ0000000QD59&p5=')

 

I created an email template with following:

<messaging:emailTemplate subject="Sample Tracking Products and Product Descriptions" recipientType="Contact" relatedToType="Sample_Tracking__c"> <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>Dear {!recipient.name},</p>       <p>Below is a list of Products and Product Descriptions cases related to the Sample Request: {!relatedTo.Id}.</p>       <p> {!relatedTo.Recipient_Contact__c}.</p>           <table border="0" >         <tr >             <th>Product</th><th>Product description</th><th>Send Quantity</th><th>Cost</th>          </tr> <apex:repeat var="cx" value="{!relatedTo.Product_Samples__r}">    <tr>        <td><a href="https://na1.salesforce.com/{!cx.id}">View</a> |         <a href="https://na1.salesforce.com/{!cx.id}/e">Edit</a></td>        <td>{!cx.name}</td>                 </tr> </apex:repeat>       </table>       <P/> </font>        </body>    </html>

</messaging:htmlEmailBody> </messaging:emailTemplate>

 

The problem I am getting is, when i click the email button the sample tracking is is not passed to the email template. And the email template don't return anything. It loads properly with contact in to box and subjects but the particular sample trackingpage from which I click the email button is not passed to the templated. So none of the related lists shows up.

 

Please suggest. I have spend about a week with no solution. Appreciate your time.

 

Thanks

Swayam

 

Sushant.ChavanSushant.Chavan

Hi Satyam,

Where you able to figure out a solution for this. I am currently struggling with the same issue.

 

Thanks,
Sushant