1

I am sending Email alerts to users when importing Accounts, but bulk uploads are failing as the daily limits are being exceeded, or, the number of emails being sent by a single SendEmail call is more than the governor limits. What can be a workaround when I cannot put a condition which will stop further Emails from being sent after governor limits are hit, as I am unable to get the number already sent?

  • Are you sending external emails or emails to internal users? – Santanu Halder Jan 31 '17 at 10:29
  • Internal users. – Sagnik Chattopadhyay Jan 31 '17 at 10:36
  • Have you tried Limits.getLimitEmailInvocations() (developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…) – mkorman Jan 31 '17 at 10:37
  • That is for the number of calls, and I am calling the method after adding all Emails to a list. So invocations are not the problem. I am invoking just twice. – Sagnik Chattopadhyay Jan 31 '17 at 10:40
  • @mkorman The question talks about the issue with number of emails sent & not number of email invocations. – Jarvis Jan 31 '17 at 10:42
2

From the salesforce docs:

Using the API or Apex, you can send single emails to a maximum of 5,000 external email addresses per day based on Greenwich Mean Time (GMT).

If you use SingleEmailMessage to email your org’s internal users, specifying the user’s ID in setTargetObjectId means the email doesn’t count toward the daily limit. However, specifying internal users’ email addresses in setToAddresses means the email does count toward the limit.

So if you are sending emails to internal users you may want to use setTargetObjectId of the SingleEmailMessage object instance.

Also, I hope you have bulkified your trigger to send all the mails of single transaction at once in the end.

  • The trigger is bulkified. But what if I need to insert/update more than 5000 records in a day? – Sagnik Chattopadhyay Jan 31 '17 at 10:52
  • The 5000 emails per day limit applied if you send emails to external emails or you specify email address while sending emails using SingleEmailMessage. But you are sending emails to internal users, so why not use the setTargetObjectId function and specify the user's Id there? It wont count towards the limit. – Santanu Halder Jan 31 '17 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.