I'm trying to send some emails using the Messaging API. I'm constructing instances of Messaging.SingleEmailMessage, setting the values of whatId, whoId, and templateId, and then sending through Messaging.sendEmail.

The problem is, the intended recipient (whoId) is a User that the running user doesn't have access to.

Is there a way I can disable this protection and send that email with the ID of any User?


Based on the requirement, you should write custom sendEmailToUser() method in the class which is marked as without sharing.

This sendEmailToUser() method will call sendEmail() for sending emails.

That way, all other logic of the existing class' method will not get impacted.

  • That wouldn't work. sendEmail() is a built-in method. – SarcasticSully Apr 16 at 19:50
  • I am talking about custom method which will call Salesforce sendEmail() method – Santanu Boral Apr 17 at 7:01

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.