Sending emails using Platform Events - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Cesar ParraCesar Parra 

Sending emails using Platform Events

I am trying to send an email that uses a Visualforce Email Template in the Trigger of a Platform Event, but I am getting the following error: System.EmailTemplateRenderException: UNKNOWN_EXCEPTION: system.security.NoAccessException: You do not have sufficient privileges to access the controller: NameOfTheVisualforceController

It seems like the Automated Process user, which is the user that triggers the Platform Event, does not have access to the email template's visualforce controller. Is there any way to give access to the controller to that user?



 
Jigar ShahJigar Shah
Cesar,

Navigate to Setup > Profiles > Search for the respective User's Profile > Edit > Apex Class Access. Identify the respective Apex Class i.e. Visualforce Controller and provide access using the Add button as per the screenshot below.

Profile Access for Visualforce Controller
Please mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
Cesar ParraCesar Parra
Jigar,

I've already tried that but the issue is that Platform Events are run through the Automated Process user and Salesforce does not let us access that user's profile. I even granted access to all profiles in my org as a test and the issues still occurs. Additionally I also made the class "without sharing" but still the issue persists.
Jigar ShahJigar Shah
Have you checked using the the Query editor in the Developer Console, if the record that you are trying to leverage is accessible to your user. If not you may need to provide access to those records by sharing them with the desired Users.

Also, use the Debug Logs to identify th epoint of falure within your Apex code and see more details around the cause of the failure.
Alia BurdickAlia Burdick
We are having the exact same issue in our org right now. Did you ever get to a resolution? 
Jigar ShahJigar Shah
Alia,

The issue is that your Visualforce Email Template has an associated Apex Controller and the user attempting to send the email does not have access to the respective Visualforce Controller.

Check the Debug Logs to identify in which User Profile's context does the code execute when the exception is encountered. You can then navigate to Setup > Profiles > Search for the respective User's Profile > Edit > Apex Class Access and provide access of the Apex class to the appropriate User Profile.
Jigar ShahJigar Shah
Alia,

If you can provide me access to your Sandbox or Dev envrionment where the issue occurs, I can take a look at it and help you get it fixed. Please reach out to me at jigar189@gmail.com.
Anoop InnocentAnoop Innocent
It's not possible to send visualforce email using platform event triggers. Please refer the knowledge articlet.

https://help.salesforce.com/articleView?id=000270230&type=1