我正在尝试通过电子邮件模板向用户发送电子邮件,但它总是将用户合并字段替换为org admin的用户名,而不是targetobjectID用户。
组织管理员:卢克·赖特
Dear {!User.Name} ,
Hearty Congratulations on this beautiful occasion. May your marriage bring great joy, love and passion in your life. I wish to God to bless you with a wonderful marriage and a happy life ahead.
Thanks and Regards.
{!Organization.Name}
OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress limit 1];
List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateID('00X0S000000iBYB'); // Template Id
mail.setSaveAsActivity(false);
mail.setTargetObjectId('0050S0000023KS9'); // UserId Name: John Doe
mail.setOrgWideEmailAddressId(owa.id);
allmsg.add(mail);
Messaging.sendEmail(allmsg,false);
问题:亲爱的{!User.Name}
应该用 john doe 代替,而用 luk wright 代替,电子邮件会正确无误。用户,即 john doe
附言。用户的合并字段未替换为该记录ID