3

The title says it all - how can you tell what folder a report is in using SOQL?

2 Answers 2

9

The field OwnerID is actually the folder ID for the Report object. I don't think you can get the folder using relationships, but you can query for reports in a particular folder:

select Name from Report where OwnerId in (select ID from Folder where DeveloperName = 'FolderName')
2
  • Thanks - I would have never figured that out. <rhetorical>Why on earth would they name the FolderId OwnerId? </rhetorical>
    – user735
    Commented Feb 4, 2015 at 22:41
  • 2
    I suspect it is because all Salesforce objects have an OwnerID field. It is a polymorphic key that typically points to a user or queue, but in this case, they took some liberties. The documentation is incorrect as well. It says "The ID of the user who currently owns this report." Commented Feb 4, 2015 at 22:45
1

As of API 35, the Report object has FolderName field.

SELECT id, name, ownerId, folderName FROM Report

The OwnerId is the ID field from the Folder object, which is the Report Folder the report lives in.

Note, the FolderName field is the label of the folder and not the unique name. So if you wanted to query for reports by their folder's unique developer name then filter by OwnerId instead like in Daniel Hoechst's answer.

SELECT id, name FROM Report WHERE ownerId IN (
    SELECT ID FROM Folder WHERE developerName = 'FolderName'
)

You must log in to answer this question.