0

Have a visualforce email template (that I had a lot of help with) that works in the "Send Test And Verify Fields" using a record ID# to test, but when the workflow calls the template for an email alert, the user gets it with only the Sample_Order__c data from the parent record, and no data from the child records referenced, its blank.

Any suggestions on how to fix this? The sharing rules for the child records are set to public read/write and there are no hidden fields so it should show

Suggestions? Here's the code:

    <messaging:emailTemplate subject="New Sample Order Notification" recipientType="User" relatedToType="Sample_Order__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>A new sample order has been requested by {!relatedTo.CreatedBy.Name}:</p>
       <br/>         
        <b>Project Name:</b>      {!relatedTo.Project_Name__r.Name}<br/>
        <b>McGrory Sales Rep:</b> {!relatedTo.McGrory_Sales_Rep__r.Name}<br/>
        <b>Company:</b>           {!relatedTo.Company__r.Name}<br/>
        <b>Contact:</b>           {!relatedTo.Contact__r.Name}<br/>
        <b>Ship To:</b>           {!relatedTo.Ship_To__c}<br/>
        <b>Notes:</b>             {!relatedTo.Notes__c}<br/>
        <br/>          

        <table border="0">
            <tr>
                <th>Quantity</th>
                <th>Description</th>
                <th>Width</th>
                <th>Height</th>
                <th>Product Code</th>
            </tr>
         <apex:repeat var="li" value="{!relatedTo.Sample_Order_Line_Items__r}">
            <tr>
                <td>{!li.Quantity__c}</td>
                <td>{!li.Description__c}</td>
                <td>{!li.Width__c}</td>
                <td>{!li.Height__c}</td>
                <td>{!li.Product_Code__c}</td>
            </tr>
          </apex:repeat>
        </table>

    </font>
   </body>
  </html>
 </messaging:htmlEmailBody>

 <messaging:plainTextEmailBody >
        A new sample order has been requested by {!relatedTo.CreatedBy.Name}:

        Project Name: {!relatedTo.Project_Name__r.Name}
        Sales Rep:    {!relatedTo.McGrory_Sales_Rep__r.Name}
        Company:      {!relatedTo.Company__r.Name} 
        Contact:      {!relatedTo.Contact__r.Name}
        Ship To:      {!relatedTo.Ship_To__c}
        Notes:        {!relatedTo.Notes__c}

        <apex:repeat var="li" value="{!relatedTo.Sample_Order_Line_Items__r}">

            Quantity: {!li.Quantity__c}
            Description: {!li.Description__c}
            Width: {!li.Width__c}
            Height: {!li.Height__c}
            Product Code: {!li.Product_Code__c}

        </apex:repeat>

    </messaging:plainTextEmailBody>

</messaging:EmailTemplate>
  • Please post the workflow logic as well, on create only? – Mike Katulka Jul 18 '17 at 18:00
0

If workflow fires on Create, then the Parent record inserts, fires email. THEN child records go in later. Order of execution problem is possibly the issue.

You might need to put in a solution to get email to fire only after child records go in. Like a rollup on children, then parent workflow on update with entry criteria where rollup > 0.

0

I think I get what you're saying. Put a rollup summary on the parent object to count # of child records, if > 0, fire the workflow, and since the child "updates" the parent record, it will fire the workflow criteria process again.

Ill give that a whirl, thanks.

0

On Email Templates, Values from child object's fields are not available. To achieve this, you need to create Visualforce Template and use Visualforce Component along with controller. In controller you can query the child records and use the values on the component. This will solve your problem. Please mark this as answer if it solves your problem. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.