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
gliugliu 

Ability to evaluate email template merge fields before sending?

Folks,

 

I've run into some problems while trying to work with email templates and visualforce/apex. We're trying to build a step-by-step wizard interface that uses emails and templates, but it looks like if a template is applied to an Apex Email Object, the merge fields are only evaluated after the email is sent. Furthermore, the template body and subject replaces any body and subject specified, which means one is not allowed to edit anything in the template before sending out.

 

For the latter problem (how to allow users to edit templates before sending), we've found a way to present the subject and body to the user, take that text in as input, and create a  temporary email template from it to apply to an email and send it. It'd be nice to have a cleaner solution to this, though.

 

For the first problem, we still have no good solution, short of parsing merge fields ourselves. Is there some secret solution for this that I'm not seeing? Some sort of way to ask the system "evaluate merge fields given a template and any necessary who/what Ids"?

 

The standard salesforce interface allows both of the behaviors above.

 

Thank,

Grant

 

 

Ispita_NavatarIspita_Navatar

The automatic evaluation does not happen and only way one can do it is writing your own code to evaluate/ parse the body of the email template and write logic to insert the appropriate field there.


However crude you may deem your solution to be but what you are doing to preview or display the body of the message is the only viable solution currently.

kool_akool_a

Hello Grant, 

 

Did you find a solution for this? Were you able to merge the fields before sending?  I don't want to have to parse the body, parsing would be very complex for us because we are using visual force email templates that have vf components embedded in the template.

 

Thanks