5

I have a full sandbox where Deliverability has been set to System Email Only. I already know how to change this to All Email but we have other reasons for not doing this (mainly we appreciate the extra safety since real user data has been cloned to the full sandbox).

I have APEX code that sends single email messages to administrators (notify that a job is done, etc). This of course throws this error:

NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile.

I'll probably end up wrapping this in a try/catch to eat the error gracefully, but I wonder if there is a way to detect the System Email Only setting in code?

I had hoped that Limits.getLimitEmailInvocations() would return 0 in my sandbox but it returns 10.

1

Exceptions are indeed the proper way to detect this condition. I used a similar method in this question to detect if BCC compliance is enabled. You'll want to look up the appropriate enum for the error you want to detect, although it should match the uppercase error code you received.

| improve this answer | |
  • Thanks. Comparing the statuscode as you did in your answer is better than my first getMessage().contains("NO_MASS_MAIL_PERMISSION") approach. – twamley Apr 24 '14 at 17:52

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.