You need to sign in to do that
Don't have an account?

Visualforce email template attach page with custom controller
Hi all,
I think the answer is no, but I'll ask anyway.
Is it possible to attach a visualforce page rendered as pdf that uses a custom controller, in a visualforce email template?
I saw a post that describes using a component, but I already have the page and the controller built...it seems that it shouldn't take much to make that available as an attachment in an email template. It's kind of silly to have to duplicate things.
Are there any workarounds?
Thanks,
--Alex
I haven't actually tried this but, I'm wondering if you could make an HTTP call from Apex to your Visualforce page that returns the PDF file and then take the resulting data and feed it into an EmailFileAttachment object. This way you could reuse the Visualforce page.
Ryan
Yes, it is possible.
You'll have to create a custom component that references the custom controller. Then, place that custom controller within the <messaging:attachment> tags of your Visualforce email template.
For example, if you have the following custom controller that finds accounts named Smith:
You would refer to this in a custom component named smithAccounts (make sure it is access global):
Then, within your Visualforce email template, you would call the custom controller within <messaging:attachment>, making sure to render it as PDF:
What if I wanted the custom controller to use information provided in the account specified by relatedToType? Is there a way for the controller class to access the account and render only contacts related to the provided account?
check my blog. Visualforce Email Template with component as attachment