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
Jacky LeeJacky Lee 

How to pass in an input string from a VF page to a VF email template?

Hi,

I'm trying to pass some string (called "greeting") that is inputted through a VF page to a VF Email Template. Right now the string goes to a controller, which goes to a component (with the html email body), which is used in the email template. The hiccup is when I'm calling a sendEmail method (which uses the templateId of the VF email template), I'm unsure how to pass that same string variable in, such that I can achieve something like this:

VF Email Template:
<messaging:emailTemplate subject="Invoice Request" recipientType="Contact" relatedToType="Account">
    <messaging:htmlEmailBody >
        <c:InvoiceRequestEmailComponent greet="{!greeting}"/>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

Where I can get the "greetings" variable from the controller and use it in the email.  When I add the component to my VF page:
<c:InvoiceRequestEmailComponent greet="{!greeting}"/>
It shows me the email body WITH the string I just entered, which makes sense as it is within that page instance. But when I send an email I can't figure out how to access the variable within my particular instance.

I think I might need to initialize a PageReference and somehow refer to that in the component, or pass in the variable in my email method. It is clear that the email template cannot access the "greetings" variable when it doesn't know what instance it's looking at, but I'm not sure how. I have also looked into the component's relatedTo and email's whatId but it seems they address sObjects field parameters, or I just can't figure out how to use them with user-inputted strings.

Thanks in advance, I can post all my code if required.