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

Email a record and its related list

I just created a custom app and it has everything the marketing group wanted. However, at the end of the approval process it needs to send an email with the contents of the record (which is no problem) AND a listing of the related items.

I'm not sure how to send that list since it could be one entry or many and it is not part of the main object. It has a lookup relationship to the main object though.


Is there a way to somehow query the related list using Apex or some other method so that I could return the items in an email?




Best Answer chosen by Admin (Salesforce Developers) 

I think Visualforce Email Templates might help you here:



All Answers


I think Visualforce Email Templates might help you here:



This was selected as the best answer
Has anyone done this type of thing before? Can you offer me some pointers?

What object are you running the approval process on?


You could use Apex and a trigger that fires only when some condition on this record is true (i.e. after the approval is completed) which runs a query for all the records in the related list, then iterates through those records to build an email body. Finally, you'd use the Apex outbound email class to create and send the email to some specified distribution list.


I am not as familiar with approval processes, but I've done similar work sending out email alerts from Apex triggers and could provide some sample code if you provide the objects you're working with.


-- Matt



just came across this and thought i could reply if this is not solved yet.  Yes, VF email templates would work for this. Set the relateTo to the mainobject(here in this case quote). A quote might have multiple items. Items have a lookup to quote.


<messaging:emailTemplate subject="...." recipientType="Contact" relatedToType="Quote">


  <apex:repeat var="cx" value="{!relatedTo.QuoteItems__r}">