3

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

8

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')
| improve this answer | |
  • Thanks - I would have never figured that out. <rhetorical>Why on earth would they name the FolderId OwnerId? </rhetorical> – user735 Feb 4 '15 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." – Daniel Hoechst Feb 4 '15 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'
)
| improve this answer | |

Your Answer

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