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?
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.