another newbie VS question.
This is how far i got (pls cf picture)
- get a list from available templates from a certain directory
- add each selected template into editable textarea
- use the edited textarea as Email Body
- choose Contact by Lookup field, add subject, cc, bcc
- 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, 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
PS: Is there maybe a way to merge/parse the template fields BEFORE they get inserted into my textarea? i.e. get the merging done, and insert those already evaluated fields. I have not found any viable way to achieve this by searching this forum and others.