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
Christian Szandor KnappChristian Szandor Knapp 

Pls confirm: Combining EmailTemplates - no way to automatically merge the template fields?

Combining Templates

Hello community, another newbie question. 

This is how far i got (the picture is almost up to date ;)):

- get a list from available templates from a certain directory
- add each selected template into editable textarea
- use the edited textarea as Email Body
- send the Email

What is obviously missing is the merging of the fields in the Email body. 

I had a look on the SingleEmailMessage(); Documentation (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sendemail.htm#SingleEmailMessage 
and also on this post https://developer.salesforce.com/forums/ForumsMain?id=906F000000094ClIAI)

It seems to me that things are getting very, very tricky at this point, if its even possible at all: As I understood in order to merge the fields approriately, I need the templateId, whatId and TargetObjectId. 

I got no problem with TargetObjectId. For WhatId it seems to be the case that might differ for each selected EmailTemplate, but if the merging of fields is really depenent on templateId, too - I can not think of any way to elegantly achieve the parsing of the templates - as I cannot provide the sendEmail method with different templateIds.

As my employer wants to be able to combine and edit templates on the fly (see screenshot), I was wondering if there is any way to achieve correct field merging without doing RegEx and stuff myself... 

If there is no other way, please point me in the right direction - I am at loss. 

Thank you for your input,

Sz

 

Christian Szandor KnappChristian Szandor Knapp
PS: Is there maybe a way to merge/parse the template fields BEFORE they get inserted into my textarea? I have not found any viable way to achieve this by searching this forum and others.
Here-n-nowHere-n-now
If your goal is to be able to send templated emails to the selected contact, a much easier way would be to use the "Send An Email" button on the related list Activity History on the contact's details page.  That button allows you to select a template already defined for the org, and merge in automatically the info in the Contact fields.