1

I am sending an email. I want to wire in my own custom object into the email.

According to the doc for SingleEmailMessage the whatIds can only be: Account, Asset, Campaign, Case, Contract, Opportunity, Order, Product, Solution, Custom

and for MassEmailMessage the whatIds can only be: Contract, Case, Opportunity, Product

So how do I wire in my own custom object?

To make matters more interesting if the target object is of type User, the setWhatIds() can't be invoked at all? How do I get around this?

Thanks.

1
  • 2
    I think for SingleEmailMessage you can also specify a custom object ID as the whatId, i've done that on numerous occasions. Commented Nov 20, 2012 at 15:49

1 Answer 1

2

setTargetObjectId() if you're using an email template.

Something like that should get you started:

Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setTargetObjectId(contactId);
msg.setWhatId(accountId);
msg.setTemplateId(emailTemplateId);
msg.SaveAsActivity = true;
// ...
Messaging.sendEmail(new Messaging.singleEmailMessage[] { msg });
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .