As we knew, in classic view folder and report are in a two-level structure. We can not create folder under folder in classic mode.

Using SOQL like (Select OwnerId,Id from Report / Select from Folder), we can get reports and folders, and display them in flat view.

Lightning has enabled nested folders as new feature. So it seems that the folder-report is no longer a flat structure.

Can we get this kind of relationship by SOQL?


It's not yet documented in the Folder field reference, but there is now a ParentId field on the Folder sObject, with child relationship name SubFolders:

relationship view

This means you can do

SELECT Id, Name, (SELECT Id, Name FROM SubFolders) FROM Folder


SELECT Id, Name, ParentId FROM Folder 

and get back details of the hierarchy. Unfortunately, Salesforce doesn't let you traverse the Parent relationship using dot notation, for reasons I don't know:

SELECT Id, Name, Parent.Name FROM Folder 


ERROR at Row:1:Column:18 Didn't understand relationship 'Parent' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.