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
nelloCnelloC 

Resolve an email template

I have built a custom VF form to send an email and I'd like to build in the same template functionality as is found on the Salesforce Send an Email form. i.e. the abilty to select a template, resolve the merge fields and place the resulting text in an email body text field on the form.

 

Does anyone know if it's possible to resolve an email template in this way? Or equally, can anyone confirm that it's not possible.

 

Thanks

paul-lmipaul-lmi

as long as you set up the email with the proper methods (setTargetObjectId and setWhatId for instance), you should be OK on merge fields.  setTemplateId is used to link the template, but the documentation seems to be missing for this method specifically.  other methods mention it, but this one isn't specifically called out in the doc.  I presume the syntax is the same for the other "set ID" methods though.

 

See "Single Email Message Methods" in the documentation for more info.

 

 

nelloCnelloC

Paul, thanks for your reply. I have in fact got it working by setting the template id on the SingleEmailMessage class when actually sending the email but what I wanted to acheive is to resolve the template before sending the email and place the resolved text in an inputTextArea on my send email form for the user to then enter their email text and subsequently click a send button. Very much like you can on the standard Salesforce Send an Email form. But I'm not sure whether this is possible

 

Regards

Neal

paul-lmipaul-lmi
this may be possible, but it's not going to be simple.  email templates are standard metadata, so you could probably use SOQL to grab the text, but the merge fields would not work at that point.  i didn't fully replace the SF default email editor for this reason, but instead, i do a form post to it to pre-populate as much as possible.  i created a VF page that acts as a template chooser, so that when they go to send an email, they actually hit this page first instead of having to launch the popup.  probably different use scenarios though.