2

My organization sends emails via Apex single email in some cases, We are sending the mails to users whenever possible, but sometimes we need to send to external mail, that's causing us to use the 1000 single email limit. Recently We are having issues of passing this limit which causes email not to be sent, or code to fail.

Except from the workbench, Is is possible to get the remaining single emails limit we've left?

The idea is to create an alert whenever the limit is approaching its limit, Any Other ideas will also be great

0

Yes, you can use the System.Limits class from Apex. Here is a link to the System Limits documentation.

//This is how many email calls have been made
System.debug(System.limits.getEmailInvocations());
//This is how many in total are allowed  
System.debug(System.limits.getLimitEmailInvocations());

Your code can look at these two numbers to work out if you are getting close to the threshold and to act accordingly.

2

Another pattern you can use is the following

try {
    Messaging.reserveSingleEmailCapacity(count);
    ... send email(s)
}
catch (System.HandledException) {
    .. alert user and say try again next day ...or
    .. alert sysad and use an async pattern to queue for next day to retry
}
  • But how would you access that from workbench? You'd need to use Apex REST, no? – Adrian Larson Aug 18 '16 at 17:46
  • @AdrianLarson - you wouldn't use the above from Workbench - only from apex code which is what I gathered from the OP is the essence of the issue - avoid sending out emails when there is no capacity to do so. Doug B had a reasonable solution as well – cropredy Aug 18 '16 at 19:36
  • Except his solution does not tell you anything about how many emails you can still send, only how many invocations of sendEmail remain. See also: salesforce.stackexchange.com/questions/137203/… – Adrian Larson Aug 18 '16 at 19:38
  • The OP certainly seems to be looking for a way to access this information via the workbench. – Adrian Larson Aug 18 '16 at 19:39

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.