I'm trying to implement a lightning-component-based custom display of email templates and their folders in a form similar to lightning:tree (a tree view with collapsible levels).
There's a nested folders structure:
- -> Folder level 1
- –> Folder level 2
-
—> Folder level 3 {
-
email template 1,
-
email template 2,
-
…
}
Every folder can contain another folder and/or Lightning Email Templates.
Now I want to query Email Templates with information in which folder it's stored.
This one is easy: [SELECT Id, Name, FolderId FROM EmailTempate... etc].
The problem is that I need to know not only the direct Folder Id/Name in which the template is stored, but also parent, grandparent and so on. Even if you start from [SELECT Id, Name FROM Folder… etc] you're not able to get parent Id.
Is there a way to achieve it?
Mateusz 🙂
Best Answer
Actually, you can get parentId of the Folder just like this:
SELECT ParentId FROM Folder
Here is the code you need to execute to retrieve all folders where email templates are stored: