+ Start a Discussion
Mike Lee PCLMike Lee PCL 

Sending SingleEmailMessage to 150 users

Hello,

I'm developing a few classes which ultimately will send summarized Contact information to users in my org on a daily basis.

The # of emails sent daily can range from 0 - 150 depending on the values stored in the Contact records. Since the emails are tailored to each user I'm using SingleEmailMessage and not using email templates.

I read here (https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_email.htm) that if I set the targetobjectID the emails sent out don't count towards our daily limit. However in order to send the message I need to specify the SettoAddress. The same document says that setting this value does count towards the limit.

Does anyone know how I can send up to 150 emails (all to internal org users) without bumping into the 100 email SingleEmailMessage limit?

Thanks,

Mike
NagendraNagendra (Salesforce Developers) 
Hi Mike,

We send numerous emails to numerous internal Salesforce users for things like job failures in Apex.  We always assumed that setting the toAddresses() field to the email address of an internal user (ie. first.last@mycompany.com) would qualify as an internal email.  After hitting some limits, we question that assumption. It appears that sending an email like this will still qualify as an external email even though there is a internal Salesforce user with that email. 

We should  use setTargetObjectId(internalUserId) to guarantee the email as counted as an internal address and will not count against our limit? Messaging.SingleEmailMessage only has the singular method setTargetObjectId() and not the plural version setTargetObjectIds().

Sample Code:

Messaging.SingleEmailMessage emailMsg = 
     new Messaging.SingleEmailMessage();  
emailMsg.setTargetObjectId(internalUserId);
//must be false if sending to internal user    
emailMSg.saveAsActivity = false; 
emailMsg.setSenderDisplayName('sender name');  
emailMsg.setSubject('some subject');  
emailMsg.setBccSender(false);  
emailMsg.setUseSignature(false);  
emailmsg.setPlainTextBody('email body');  
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { emailMsg });

I believe this is correct. You'll have to create multiple copies of the email and set the target object ID to each recipient user. You can send several mails at once, just add them all to a List<SingleEmailMessage>.

To add, please note :

  • setTargetObjectId to Contact does count in limit
  • setTargetObjectId to User does NOT count in limit.
Mark, it as solved if it helps.

Best Regards,
Nagendra.P