If the Compliance BCC Email setting is enabled email messages cannot be sent with custom BCC addresses e.g.

Messaging.SingleEmailMessage toSend = new Messaging.SingleEmailMessage();
toSend.setToAddresses(new List<string>(){'abe@example.com'});
toSend.setBccAddresses(new List<string>(){'bee@example.com'});
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ toSend });


I would like to be able to detect if this setting is set so I can prevent BCC addresses from being set.

What I've done so far:

Googling has thus far only led me to the documentation which gives no real pointers on this. If it's not possible there is always the possibility of just doing a test email that will detect the issue however I'm hoping to avoid that.


You can send a test message with no parameters, and check the resulting error code. BCC Compliance is checked before other validations, so this should be reliable.

Boolean bccComplianceEnabled;
Messaging.SingleEmailMessage m = new messaging.singleEmailmessage();
m.bccsender = true;
try {
Messaging.sendEmail(new messaging.singleemailmessage[] { m });
} catch(emailexception e) {
    bccComplianceEnabled = e.getDmlType(0) == StatusCode.BCC_NOT_ALLOWED_IF_BCC_COMPLIANCE_ENABLED;

Note that the email won't be sent, because we do not specify a target address or any other values; BCC compliance is checked before any other tests.

  • I updated the code with a new version I tested in my Developer Edition. This should be reliable, as far as I can tell. – sfdcfox Aug 26 '13 at 15:04
  • While I was hoping to avoid this pattern it seems the only viable solution unless salesforce exposes the setting. – Mgetz Aug 26 '13 at 15:14
  • 1
    If there is, I'd love to know about it. Having been with salesforce.com technical support for years, I've learned that hacks are quite frequently necessary to work with salesforce.com. Granted, it's still a far better platform compared to most others I've experienced... – sfdcfox Aug 26 '13 at 15:25

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.