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
BrianWKBrianWK 

Visualforce Email Controller Extension or Email Visualforce page as body and not Attachment

Hello everyone.
 
I've successfully created my first page that required a custom controller extension. Thanks to everyone who help me fumbled through it.
 
I have a current page on a custom object (Implementation__c) with a extension containing SOQL to build a list of related objects (Implementation_Issue__c). The Implementation_Issue__c is a standard object with a look up to Implementation__c, a detail object with a master to Account.
 
The page works perfectly. Originally, I had planned on Rendering the page as PDF and attaching the PDF to an email to our clients. It has been requested that the page becomes the body of the email and not an attachment.
 
I'm struggling here, it doesn't appear I can use <Apex:page> within a visualforce email template. So I'm not sure how can I call the controller extension for my relatedto:Implementation__c object.
 
Anyone have an idea how I can accomplish this? My thoughts are:
 
1. Somehow call my Implementation__c extension within the email template (not sure how or if I can do this)
2. Change the Implementation__c extension to by an extension for the email template (<messaging:emailTemplate> ?)
3. Keep my extension and page as is, but use code to set it as an email (not sure if this is possible either)
 
Again, my goal is to use this page as the body of the email and not as an attachment. I haven't been able to see how to call a custom controller or an extension within an Visualforce Email template, or what the controller for an email template is to create a new extension to give me the functionality I need.
 
Any help, suggestions are most welcomed!
ftitftit

Having a similar issue!

I guess we need to know the equivalent structure to:

Code:
<apex:page controller="Apex Class">
.....

for VS email templates.

If you find an answer, let me know!
 

BrianWKBrianWK
Ftit, I ended up not going the Visualforce Template. Right now they simply cannot give me what we needed. We ended up creating a separate page to mimic the "Send Email" function and using it to forward to the PDF page and attach as an email. We've tried using the template to past the RelatedTo.ID to the controller of the PDF page but I didn't have any success with that.
dchasmandchasman
Usually I have been able to work around the current VF Email Template limitation of not allow custom controllers /or extensions by creating a custom component (hint: these can have custom controllers) and using that inside the template. Take a look at this post for an example of what I am talking about.
Onur Kaya 9Onur Kaya 9
You can create a custom component and use controller logic on the componnet. Then all you need is to inser the component into VisualForce email.

To create a custom component check the link below;

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

The custom component should look like this in visualforce email

<messaging:htmlEmailBody >
<c:CustomComponent customRecordId="{!relatedTo.Id}"></c:FSProjects>
</messaging:htmlEmailBody >