1

I am creating an email template which will be sent to individual contacts, the template needs to list rows from a related object. I have created the relevant component and class which I believe would have achieved this however I have come across some issues:

relatedTo Contact details are not loaded
I get the following error when trying to save the email template when using my Contact fields

Error: Invalid field Contact for SObject Account

The line in question is {!relatedTo.Contact.Name}

Email Template:

<messaging:emailTemplate subject="My email subject" recipientType="Contact" relatedToType="Account">
<messaging:htmlEmailBody >

    <p><apex:outputText value="{!TODAY()}" /></p>

    <p>REF: <apex:outputText value="{!relatedTo.Name}" /></p>

    <p>Dear {!relatedTo.Contact.Name},</p>

    <c:ORCLetter_Component acctId="{!relatedTo.Id}"/>

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

1 Answer 1

2

The syntax you used:

{!relatedTo.Contact.Name}

presumes that there is a lookup relationship from Account to Contact. But there isn't. There is a lookup relationship from Contact to Account. That is, relatedTo references the relatedToType

<messaging:emailTemplate subject="My email subject" recipientType="Contact" relatedToType="Account" 

on your <messaging:emailTemplate> component

To refer to the Contact's name, you would use

{!recipient.firstname} {!recipient.lastName}

see the VF doc here.

You must log in to answer this question.

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