For some reason, whenever I query EmailTemplates or Folders in Apex, all of the EmailTemplates or Folders are returned regardless of User. Usually queries only return records the current User has permissions to view (at minimum). How can I query for only the EmailTemplates the current User has access to (based on the permissions defined in Email Folders)?
Here's what I have so far:
Set<ID> FolderIds = new Set<ID>();
List<Folder> Folders = [Select Id, Name From Folder Where Type = 'Email'];
for(Folder F : Folders) { FolderIds.add(F.Id); }
List<EmailTemplate> Templates = [Select Id, Name, IsActive, Folder.Name
From EmailTemplate
Where IsActive = true
And Folder.Id IN :FolderIds
ORDER BY Folder.Name, Name];
I figured it out. I needed to add "with sharing" to my custom class definition. That took the User's permissions into consideration when querying.