Find your content:

Search form

You are here

How do wire in my own Custom Object into an email


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?


Attribution to: dublintech

Possible Suggestion/Solution #1

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

Something like that should get you started:

Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.SaveAsActivity = true;
// ...
Messaging.sendEmail(new Messaging.singleEmailMessage[] { msg });

Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content