0

I'm writing an Email template that includes merged fields,

When I add an account field it works fine,

But when I try to add a field from a custom object it does not work,

As I mentioned above I have done it manually, by setting the "Related To" to the custom object record But when I use the following code, the included field is blank in the template

Inquery__c inquery = trigger.new[0];
 String[] toAddresses = new String[] {inquery.email__c};
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  mail.setTargetObjectId(inquery.OwnerID);
 mail.setSenderDisplayName('Salesforce Support');
  mail.setUseSignature(false);
  mail.setBccSender(false);
  mail.setSaveAsActivity(false);
 EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Invitation_to_register_for_Training'];
 mail.setTemplateId(et.id);
 Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

I tried to add the setWhatID as follows,

mail.setWhatId(inquery.OwnerID);

But it gave me an error stating: WhatId is not available for sending emails to UserIds

Thanks

4

1 回答 1

1

在 setWhatId() 方法中,您必须插入查询 ID 而不是 OwnerID 字段:

mail.setWhatId(inquery.ID);

尝试修复它。

于 2013-07-23T10:35:40.177 回答