I’m trying to query the EmailTemplate object in Salesforce with WITH SECURITY_ENFORCED to respect CRUD/FLS, but I get an error even though the user has access to Email Templates.
List<EmailTemplate> templates = [
SELECT Id, Name, Subject, Body
FROM EmailTemplate
WHERE DeveloperName = 'Offer_Letter_Template'
WITH SECURITY_ENFORCED
];
{
"error": "Insufficient permissions: secure query included inaccessible field",
"success": false
}
Why does this error occur even when access is granted?
I wrote a SOQL query on EmailTemplate with WITH SECURITY_ENFORCED because I wanted Salesforce to automatically enforce CRUD/FLS.
I verified that the user profile has access to the Email Template object and the queried fields (Id, Name, Subject, Body).