+ Start a Discussion

Apex Mass email on Custom object

I would like to make a mass email function based on the email addresses of a custom object email field.

I just see in the Developer's Guide, that the Mass email methods are only for the standard "contact, lead, or user" objects.

But what if I want to send emails to a custom object email field?? There is no way? I could not imagine that.

Please help me out!



You can use the Messaging class to build your own Mass Email functionality. You can specify the email address to which you wish to send an email.


I know I could use it, but my records with the referred email addresses are in a custom object. The documentation says the TargetObjectID method is only for the above mentioned standard objects.

So, I would like to make a list of them with a SOQL query and I would like to send to these email addresses the message.

Do you understand what I mean?



Unfortunately, you've read the documentation correctly - you can only send Mass Email Messages to Contact, Lead or User records via Apex. You can only send Single Email Messages to an email address stored on a custom object. 


That was I was afraid of, if someone know any workaround dont hesitate to share with us!!!

( I have to add, I really don't understand the reason for this limitation, its a huge, huge drawback)


I havent tried it but I think you can generate a list of Single emails and send them in bulk.

Imran MohammedImran Mohammed

I dont know whether this will work for you or not,

If the email address in the custom objects are similar to the email addresses in User or Contact or Lead object for each record.

Create a lookup to the User or Contact or Lead on the current custom object where you have the email address and then pass the lookupid value to the targetObjectIds.


Thank you for your suggestion, but the problem is, I can't use the standard built in Salesforce objects, bacuse it will be a full custom Force.com organization.




For now there is no possibility to use Mass Email using Custom Object, but a work around with limitations you may have using Messaging.SingleEmailMessage, just add all the email ids in a String array ( As you add for List)  and pass the String Array to the mail.setToAddresses(EmailID);


The Limitation Are:

1. You can not have the different Email Template.

2. Everyone in your email to list will be visible to each other.


If any more , pls let us know- :)


I thought that Accounts and Contacts aree allowed in all ORGs.


We build native Force.com applications and we have our email addresses in a custom object. We loop through them and create a list of contact objects. Then use those constacts to send the emails. Afterwards, we delete them and empty them from the recycle bin.


Don't try this with users because they are never deleted, only set inactive.