SalesForce Visualforce email template Apex Controller

Viewed 40

I have an assignment. I need to send to different contacts the participants associated with it using visualforce template in pdf format. I know how send email to different recipients, but i dont know how to send with different text. When I do SOQL in my controller I have List of List (Contacts and Participants) but how send to different contacts with different text body i dont know

1 Answers

Visualforce email template can't have an apex controller like say a vf page. BUT it can include a vf component - and that component can have controller and accept parameters!

It's bit trickier than usual because you'd need to move some logic to getter but it's doable. Make a component, pass to it "related to.Id" or something and it'll work

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm

https://salesforce.stackexchange.com/q/245930/799

There's my ancient answer https://salesforce.stackexchange.com/q/4303/799 if you're still stuck, overcomplicated for what you need but hey, gives some ideas.

Remember that each such email + component + controller will count to limit of soqls. If it uses 1 query (gimme participants for this contact id) - that's max 100 emails in single transaction.

Related