0

Hi SalesForce Community.

I am hoping you can help,I have encountered different issues with my email template, and i have searched different forums and getting my self more and more confused. To give some context I am trying to Create a VF email template that returns fields from the related list on the sales_and_marketing__c object.

I have three objects in question (See Two images attached) sales_and_marketing__c, Material_Records__c, Material Records Materials_Junction__cMaterial Junction

When on the sales_and_marketing__c object there is a related list. When you scroll down to the related list and click on new it opens up a pop up box which is the Materials_Junction__c. Related List On Sales MKT Object

Materials_Junction__c object has three fields (see Material Junction photo)

When you click on the magnifying class on "Material record" fields you are presenting with the following.Material Selection this is the Material_Records__c object.

After selecting your materials you will return to this screen(See below) you add in a quantity amount and press saveadding quantity amount

Once you push "save" the materials you have selected along with quantity will be presented on the sales_marketing object (as seen below)Final Outcome

On my email template i should see.

Name of "Sales and Marketing" Record ( so example above it would be "Test") Then 5 lines to show the products, item , quantity

Recap : Products and Item comes from the Material_Records__c object, and quantity from the Materials_Junction__c object

This is my attempt at my VF Page

    <messaging:emailTemplate recipientType="Contact"
relatedToType="sales_and_marketing__c"
subject="Testing VF page: {!relatedTo.name}">

<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 materials related to : {!relatedTo.name}.</p>

<table border="0" >
    <tr > 
        <th>Action</th><th>Case Number</th><th>Subject</th><th>Creator Email</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
        <tr>
            <td><a href="https://na1.salesforce.com/{!cx.Materials_Record__c}">View</a> |
            <a href="https://na1.salesforce.com/{!cx.Materials_Record__c}/e">Edit</a></td>
              <td>{!cx.Materials_Record__r.Product__c}</td>
        <td>{!cx.Materials_Record__r.Active__c}</td>
        <td>{!cx.Materials_Record__r.Item__c}</td>
            </tr>
    </apex:repeat>                 
</table>
<p />
     </font>
        </body>
    </html>
</messaging:htmlEmailBody> 

<messaging:plainTextEmailBody>

Dear {!recipient.name},

Below is a list of cases related to Account: {!relatedTo.name}

[ product ] - [ active ] - [ Itemss] 

<apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
[ {!cx.Materials_Record__r.Product__c} ] - [ {!cx.Materials_Record__r.Active__c} ] - [{!cx.Materials_Record__r.Item__c} ]  
</apex:repeat>

For more information login to http://www.salesforce.com
</messaging:plainTextEmailBody>    
</messaging:emailTemplate>

2 Answers 2

1

One obvious mistake is that you're trying to iterate over a reference (lookup) field:

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

Which implies that Material_Records__c is actually the lookup field on Materials_Junction__c list. So, it is complaining about the Id field because the value returned to cx is an Id, and of course [some id].Id is not valid.

To 'repeat' over a list of records, you need to iterate over the relationship record, denoted by the __r

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

However, I think your relatedTo object needs to be Sales__c (or Sales & Marketing?) object and then you'd iterate as follows (though I can't be sure what you've named your lookup relationships).

<apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
    <tr>
        <td><a href="https://na1.salesforce.com/{!cx.Materials_Record__c}">View</a> |
        <a href="https://na1.salesforce.com/{!cx.Materials_Record__c}/e">Edit</a></td>
        <td>{!cx.Materials_Record__r.Product__c}</td>
        <td>{!cx.Materials_Record__r.Active__c}</td>
        <td>{!cx.Materials_Record__r.Item__c}</td>
    </tr>
</apex:repeat>
11
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review Commented Nov 10, 2016 at 19:49
  • 1
    You might want to phrase this differently so it does not look like a question itself.
    – Adrian Larson
    Commented Nov 10, 2016 at 19:56
  • @ Adrian & batter.cord I have rephrased the title and body of the question. Please let me know if the question isn't clear . -I appreciate your feedback
    – Masond3
    Commented Nov 10, 2016 at 20:02
  • Point taken @battery.cord, edited Commented Nov 10, 2016 at 20:06
  • 1
    Hi Phil- that does make sense. Unfortunately I don't have access to my pc so unable to give your recommendations a ago. I will try this first time thing at work tomorrow morning :)
    – Masond3
    Commented Nov 10, 2016 at 20:41
0

Would like to thank @PhilHawthorn for helping me through this. Phil established that the error i was getting was due to the Materials_Junction__r does not exist.

He then realized i named the related list name, Materials, thus making the relationship Materials__r not Materials_Junction__r.

<messaging:emailTemplate recipientType="Contact"
relatedToType="sales_and_marketing__c"
subject="Testing VF page: {!relatedTo.name}">

<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 materials related to : {!relatedTo.name}.</p>

<table border="0" >
    <tr > 

       <th>Product</th><th>Item</th><th>Quantity</th>


    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Materials__r}">
       [ {!cx.Material_Records__c} ] 

        <tr>
              <td>{!cx.Material_Records__r.Product__c}</td>
              <td>{!cx.Material_Records__r.Item__c}</td>
              <td>{!cx.Quantity__c}</td>
            </tr>
    </apex:repeat>                 
</table>
<p />
     </font>
        </body>
    </html>
</messaging:htmlEmailBody> 

<messaging:plainTextEmailBody >

Dear {!recipient.name},

Below is a list of cases related to Account: {!relatedTo.name}

[Product] - [Item] - [Quantity] 

<apex:repeat var="cx" value="{!relatedTo.Materials__r}">
[ {!cx.Quantity__c} ]   
</apex:repeat>

For more information login to http://www.salesforce.com
</messaging:plainTextEmailBody>    
</messaging:emailTemplate>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .