从 Apex 调用时的自定义电子邮件模板合并字段

问题描述

我有一个在 Apex 代码中引用的现有自定义电子邮件模板。 我在这个电子邮件模板中添加了两个合并字段 Lead.Name、Lead.Company

当我单击“发送测试并验证合并字段”时,我可以看到合并的值。 但是,当从 Apex 类调用电子邮件模板时,不会合并字段值。

附上代码片段。

 public PageReference sendDoc(){
    Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();
    email.setToAddresses(new List<String>{ReceiverEmail});
    EmailTemplate template = [Select id,HTMLValue,Subject from EmailTemplate where DeveloperName =: Label.Form_Submission_EmailTemplate];
    String str = template.HTMLvalue;
    str = str.replace('{leadurl}',Label.Sample_Site_URL+leadId+'&sendDoc=true" type="button"><b>Submit </b></a>');
            
    email.setHTMLBody(str);
    email.setSubject(template.Subject);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
    return new PageReference('/' + leadId );

}

收到的邮件是这样的

enter image description here

电子邮件模板

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)