2

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]; 
Matt K
  • 7,207
  • 5
  • 39
  • 60
  • As this is now 'answered' please could you add your update as an answer and marked this question as answered? Otherwise it will continue to appear to be unanswered. – Born2BeMild May 22 '12 at 08:03

1 Answers1

0

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.

Matt K
  • 7,207
  • 5
  • 39
  • 60