+ Start a Discussion
Lago S.p.a.Lago S.p.a. 

Use parent object field on visualforce template

Hi everyone! I've a little problem with a visualforce template.
I'd like to add in this template various fields on account parent object, but when I test with a test contact, I don't see any field of the related account :(
Here's a part of my code:
<messaging:emailTemplate recipientType="Contact"
    relatedToType="Contact"
    subject="CONDICIONES COMERCIALES PARA EL AÑO 2020"
    replyTo="web@lago.it" 
    >
    
<messaging:htmlEmailBody >        
    <html>
        <body>
            <div>
                <img src="https://www.lago.it/wp-content/uploads/2020/02/header-mail.png" style="width:60%;margin:5% 40% 5% 0%" border="0"></img>
            </div>
            <div style="margin-left: 40%;width:60%" align="left">
                <apex:variable var="Name" value="{!relatedTo.Account.Name}" />
                {!Name}<br/>
                {!relatedTo.Account.BillingStreet},{!relatedTo.Account.BillingCity}<br/>
                {!relatedTo.Account.BillingPostalCode},{!relatedTo.Account.BillingCountry}<br/>
                <apex:outputText id="PIVA" rendered="{!IF(relatedTo.Account.piva__c <> '' , 'true', 'false')}">
                    CIF: {!relatedTo.Account.piva__c}<br/> etc etc....

Any help will be appreciated..Have a nice day :)
Best Answer chosen by Lago S.p.a.
Lago S.p.a.Lago S.p.a.
Hi, I've solved without Apex code. There's a problem in SF when you use the preview to send an email from the contact instead of use directly a workflow rule that triggers the email sending (yes, it's not possiible to send mass email with visualforce template).
So, my code was right. The preview in send email button from contact is the real issue. Have a nice day

All Answers

Danish HodaDanish Hoda
Hi there,
Try using VF component and search for the fields of the Parent Account's fields on it's extension class' constructor.
Lago S.p.a.Lago S.p.a.
Hi, thanks for you response Danish. Do you mean to write apex code?
Danish HodaDanish Hoda
Yes
Lago S.p.a.Lago S.p.a.
Hi, I've solved without Apex code. There's a problem in SF when you use the preview to send an email from the contact instead of use directly a workflow rule that triggers the email sending (yes, it's not possiible to send mass email with visualforce template).
So, my code was right. The preview in send email button from contact is the real issue. Have a nice day
This was selected as the best answer