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
June BischoffJune Bischoff 

Trouble accessing lookup-related custom object in a Visualforce Email Template

I'm fairly new to Visualforce.  I'm working with custom objects in a managed package, attempting to create an email template with a table of related detail rows.  My visualforce email template is set to use the custom object "Sales Order":

<messaging:emailTemplate recipientType="Contact"
    relatedToType="PBSI__PBSI_Sales_Order__c"
    subject="Order and Shipping Confirmation for PO {!relatedTo.PBSI__Customer_Purchase_Order__c}">    
<messaging:htmlEmailBody > 

And I'm trying to access a related list custom object (Shipped Sales Order Lines) that has a lookup to the Sales Order but not a master/detail relationship.  
<apex:repeat var="ssoLine" value="{!relatedTo.PBSI__Shipped_Sales_Order_Lines__r}">

I'm getting an error :   [Error] Error: Invalid field PBSI__Shipped_Sales_Order_Lines__r for SObject PBSI__PBSI_Sales_Order__c.

I've tried using {!relatedTo.PBSI__Shipped_Sales_Order_Lines__r} as well as {!relatedTo.PBSI__Shipped_Sales_Order_Line__r}, but no luck.  Will this work with a lookup field relationship, or does it need to be master-detail?  How can I find the correct API Name if it is possible with only a Lookup?  If it's not possible, do I need to go the custom component/controller route, or are there other methods to access the related data?

Thanks in advance!

Shipped Sales Order Line info:
Singular Label: Packed Sales Order Line 
Plural Label: Shipped Sales Order Lines 
Object Name: Shipped_Sales_Order_Line 
API Name: PBSI__Shipped_Sales_Order_Line__c

Lookup field on Shipped Sales Order Line
Field Label  API Name                     Installed Package   Data Type
Sales Order PBSI__Sales_Order__c Ascent4Salesforce Lookup(Sales Order)

As a side note, I am able to access related Sales Order Lines, which do have a master/detail relationship to the Sales Order:
<table>
    <apex:repeat var="soLine" value="{!relatedTo.PBSI__Sales_Order_Lines__r}">
    <tr>
        <td width="20%">{!soLine.PBSI__Item__r.Name}</td>
        <td align="center">{!ROUND(soLine.PBSI__Quantity_Needed__c,0)}</td>
    </tr>
    </apex:repeat>   
</table>

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

Unfortunately it will not work as Salesforce does not support cross object merge fields in email template. There is an idea ongoing, you can vote for it: https://success.salesforce.com/ideaview?id=08730000000Brk7AAC (https://success.salesforce.com/ideaview?id=08730000000Brk7AAC" target="_blank)

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
June BischoffJune Bischoff
Thank you for confirming that, Zuinglio.  Is there a workaround?  Is it time for me to try to figure out how custom components and controllers work, or do I just give up and wait?