We are executing some asynchronous code that uses getContentAsPdf
on a Visualforce page as the result of handling custom platform event and we get this error in the Apex Jobs listing:
First error: [UNKNOWN_EXCEPTION] You do not have sufficient privileges to access the controller: LetterController
The "Automated Process" user (and its profile) that the events are handled under is pre-defined and not editable. And profiles would normally enforce access on the Visualforce page not the Apex controller so this error is inconsistent with that.
This looks like the same problem as this unanswered question from 6 months ago Automated Process User Permissions. (And perhaps this is related too: Salesforce doesn't merge fields on email sent in platform event context.)
Another piece of code that uses Messaging.sendEmail
fails silently i.e. the message is not sent but the isSuccess()
method of the result is true.
We will create a case with Salesforce about these, but has anyone done so and got these accepted as a defects? Or found a way to avoid the problems?
(The problem we are trying to solve using Platform Events is Running a Batchable under a different User than the User that called Database.executeBatch.)