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
melfmelf 

VF Email Template for Parent and Child Account

Hello,

 

I am trying to create a visualforce email template that will send a user a list of Account and Contact data.  I want to include Parent and Child Accounts and all related Contacts.  So far I can get the Contacts list as it relates to an Account with the below code, but this does not include the data for the Child Account if I choose the Parent.

 

My use case is this:  if opportunity stage = Closed Won send an email to a list of users welcoming our new client.  The email should include all Parent and child accounts including all related contacts.

 

 

<messaging:emailTemplate subject="New Client" recipientType="User" relatedToType="Account"> <messaging:HtmlEmailBody > Account Name : {!Relatedto.Name} <br/> Account Address: {!Relatedto.BillingStreet} <br/> Account City: {!Relatedto.Billingcity} <br/> Account State: {!Relatedto.BillingState} <br/> <apex:repeat var="cx" value="{!relatedTo.Contacts}"> Contact Name: {!cx.name}<br/> Contact Address:{!cx.mailingstreet}<br/> Contact Email:{!cx.email}<br/> </apex:repeat> <br/> </messaging:HtmlEmailBody> </messaging:emailTemplate>

 

 Thanks

 

gtuerkgtuerk
Do you have any appetite for using a Custom Controller?  You could have a component encapsulate your markup and have an apex:attribute in the component that you set with the relatedTo.Id.  The you use that ID to query for child accounts, pack them in  a list and use the list of ids to query against contact.  It's pretty simple like that
melfmelf

Thanks for the info gtuerk  -

 

At this point I am still more of an intermediate admin type with no developer skills.  I'll dig into the documentation regarding custom controllers and see if I can figure it out.

 

Thanks