0

I have a requirement to send emails to external users using apex code , but the email limit is 5000 per day using single email messaging class.

I am using a batch job to send email , but before I get the number of records to whom I need to send email I want to know how much is the email limit left for today. Is there way to query the limit in apex code to check how much email limit is left for a day?

4
  • Actually, that is the wrong duplicate. In that question, the OP had a problem where he was making too many sendEmail calls within a context. In this case, the OP has a problem with the daily limit – Sebastian Kessel Oct 18 '16 at 18:14
  • 1
    @SebastianKessel Hmm, the answer there seems to contain the answer to this question as I read it. Do you think there is a different dupe out there or that this is a new question? – Adrian Larson Oct 18 '16 at 18:15
  • It does, but on a tangential way. The question doesn't ask for it. A casual reader might not see the nuance or the difference between both answers. – Sebastian Kessel Oct 18 '16 at 21:15
  • And this has been asked by the OP before. salesforce.stackexchange.com/questions/143961/… – Eric Oct 18 '16 at 21:59
0

UPDATED ANSWER:

Turns out, the Limits class is now what you need. I'll go back to what I used to do.

You can use Messaging.reserveMassEmailCapacity(count);. This call will result in an error if you don't have enough capacity. It's not exactly what you asked, but it could do the trick in your case.

Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_forcecom_email_outbound.htm

Also, vote the idea that would expose this limit via the class above: https://success.salesforce.com/ideaView?id=08730000000aSLLAA2

13
  • Nope. That gives you the current context limit, not the daily limit. – Adrian Larson Oct 18 '16 at 18:05
  • 2
    Damnit. Why don't I properly read my own links? – Sebastian Kessel Oct 18 '16 at 18:07
  • 1
    Also the OP totally accepted the wrong answer here after I made the same mixup. – Adrian Larson Oct 18 '16 at 18:08
  • 1
    That Limits method returns how many times you can call Messaging.sendEmail, which is indeed 10. You should replace count with the number of emails to verify. – Adrian Larson Oct 18 '16 at 18:29
  • 1
    You can call sendEmail once on a List that contains 5000 emails. – Adrian Larson Oct 18 '16 at 19:04

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