I have Contacts object (contains the employees) and a Custom object called Organizations (which has the list of companies) and they are related using Lookup relationship (there is a lookup field on contacts which populates the company. There is also custom field on Contacts called "Allowances".

The requirement is, an email should be sent to every company about the employees that are a part of it and also the allowances each of them is given. I have researched this and I think this can resolved by using the VF page email templates. Is my approach correct or is there any better solution to achieve this.

I've gone through a related issue but did not quite understand it .

  • VF email template is good for this. Aug 8, 2016 at 16:29
  • A visualforce email template allows you to customize exactly what your email looks like, and allows you to incorporate fields and apex calculations in a similar way to visualforce pages. However, when it comes to sending those emails, standard email alert functionality still applies, just as if you were using a standard text template. Just an FYI.
    – smohyee
    Aug 8, 2016 at 17:26

1 Answer 1


Here's the broad strokes of what I'd do:

  1. Create a custom Apex controller to use with your visualforce template. The main purpose of this controller would be to use a SOQL query to return a list of all related contacts and their allowances for each organization's email. (Reference)

  2. In the VF email template, display the results of above Contact SOQL query using an <apex:dataTable> component. One column listing contact names, another column listing their 'Allowance' field. (Reference)

  3. Finally, I'd need a way to trigger said email template to be sent to a list of Organizations. Rather than using a standard email alert Workflow Rule, I'd assume this is the kind of email you'd want to mass send to all clients at once. To facilitate that, I'd write an apex class that would build a list of email addresses (pulled from a SOQL on the Organization object), and send them the above email template. This class could be triggered via code from the dev console, it could be a scheduled apex class, or tied to a button somewhere on your SF UI.

You must log in to answer this question.

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