8

I'm comfortable with sending emails using APEX and using mailmerge within that process. What I want to do now is load an email template, mailmerge it automatically using a predetermined contact ID and then place the output in a WYSIWYG editor. After which I would like to be able to convert the WYSIWYG editor content into an email and send it.

For an example please look at /_ui/core/email/author/EmailAuthor, select a contact and then click the Select Template button and select a template. The template will be dropped in a WYSIWYG editor and then clicking Send will work.

I'm able to load an EmailTemplate's Body and place it in a WYSIWYG editor but then

  1. I don't have mailmerge fields populated.
  2. Setting the data from the WYSIWYG editor as the htmlValue of an Email throws an FIELD_INTEGRITY_EXCEPTION error when I attempt to send it because the WYSIWYG editor doesn't feed out the same format of data.
0

If you used something along the lines of button code (or the equivalent) to populate the fields in the existing template as the template is being loaded into the WYSIWYG editor, you could then process the edited content using single email messaging. The entire merged body would need to be processed as either html or text. That's the only way I can think of that you could make this work without first saving the edited template and then "re-merging" it with your single record to send it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.