-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logger Error Emails eat up Single Email limit #369
Comments
@EoghanMcMullen thanks so much for providing all of this information, this is incredibly helpful! I have another open issue #348 for some other enhancements related to sending emails, so I'm hoping to make a few email-related enhancements in the near future - I'll include your suggestions at part of that work. I also like your idea of having a custom setting field on |
…argetObjectId() when sending failure emails to internal users
…argetObjectId() when sending failure emails to internal users
…argetObjectId() when sending failure emails to internal users
* Fixed #369 by using instance method Messaging.SingleEmailMessage.setTargetObjectId() when sending failure emails to internal users * Updated build.yml to delete all profiles in the unsorted directory before generating package versions, because they sometimes upset the sf cli ᕕ( ᐛ )ᕗ
@EoghanMcMullen this is finally fixed in the latest release, |
Package Edition of Nebula Logger
Unlocked Package
Package Version of Nebula Logger
v5
New Bug Summary
In a scenario where many errors are generated, the Email functionality will very quickly eat up the SingleEmail limit for the org. This can have severe consequences to other processes in the org.
I ran into this issue when the following error was being thrown in quick succession:
"Logger failed to save 1 LogEntryTag__c records for : Required fields are missing: [Logger Tag]"
Preventing the error above from happening is one thing but we can also improve the way emails are sent to prevent them from having an impact on the SingleEmail limit.
In LoggerEmailUtils.queryApexErrrorRecipients a query is run to retrieve UserId/Email for the target receivers.
Then in sendErrorEmail the Messaging.SingleEmailMessage.setToAddresses method is used. The list passed to this method could contain UserIds or Email Addresses. The issue is, regardless of Email or User Id passed to this method it will eat up a SingleEmail limit.
To avoid eating up the limit we can leverage the setTargetObjectId method. This only works if we target User Ids but I'd be surprised if many people do not have a User in the ApexEmailNotification setting. If this was the case a forwarding rule could be leveraged to send to non Salesforce users.
The code ends up looking something like this:
If you still wanted to target the 'External Email Addresses' then you could split the sending into two. One for UserIds, one for Email Addresses. This way only each External Email Address eats up a limit. The limit is per Email address, not per invocation of Messaging.sendEmail.
As an FYI to confirm all this I've been running testing against the Limits API to confirm my findings.
Hope this helps out. Would also love to see a Custom Setting for disabling Emails.
Thanks again for all your hard work.
The text was updated successfully, but these errors were encountered: