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
Wei Dong 10Wei Dong 10 

How to use tokens with binding fields in a email template?

Hi all,

I created an Email template, with some fields binding such as {!Case.CaseNumber},……. My template looks like this following:
 
<table border="1" style="text-align:left;width:600">
        <tr>
            <th width="100%" colspan="4">Case: {!Case.CaseNumber}</th>
        </tr>
        <tr>
            <th width="100%" colspan="4">NOTES/VERBATIM:</th>
        </tr>
        {notes}
        <tr>
            <th width="25%">Case No:</th>
            <td width="25%">{!Case.CaseNumber}</td>
            <td width="25%">&nbsp;</td>
            <td width="25%">&nbsp;</td>
        </tr>
</table>
However, I have another customized object called "Note", So one Case may have 0 or many notes.

What puzzled me is that I want to dynamically generate rows in a table (one note one row dynamically).  So in my email template I have a token called "{notes}", what I want to do is to:

a) Get HtmlValue from the email template.
b) Use "String.Replace" to replace the fixed string "{notes}" with my own data.

But how to send email with that? You know that I've dynamically changed the email template and I don't want to make {!Case.CaseNumber} lost or something wrong.... So my final question is:

Is it possible to dynamically change the EmailTemplate (some part) but just keep its binding fields? Any good solutions or examples?