4

Short story: What is the best way to query for a list of reports in the 'Unfiled Public Report' folder.

Long story:

When I want to get a list of reports from a specific folder in apex I make a SOQL query like this:

SELECT Id,Name FROM Report WHERE OwnerId = :folderId

When I want a list of reports from Unfiled Public Reports in apex how would I do that? As far as I know Unfiled Publif Reports doesn't have a folder id.

I was able to get a list of reports by using the OwnerId of the organization. Like this:

SELECT Id,Name FROM Report WHERE OwnerId = :OrgID

Only was able to find that from this question about setting owner.

Turns out the OwnerId is a great way to get the list. Using the way of getting the OrgId programmatically from frontendloader my code turned out like this.

[SELECT Id,Name from Report WHERE OwnerID = :UserInfo.getOrganizationId()];

Interesting note: Found an answer on the Salesforce IdeaExchange from 5 years ago that talks about the folder name being unfiled$public but I am unable to get that to work. Also can't find confirmation of that. Only see it in unrelated source code here.

3

You seem to have answered your own question here.

Any report in the 'Unfiled Public Reports' folder will have an OwnerId of your OrgId. You should be able to reference your OrgId programmatically when you query for it, something like:

[SELECT Id,Name from Report WHERE OwnerID = :UserInfo.getOrganizationId()];
| improve this answer | |
  • I didn't want to use OwnerId because I didn't know if only unfiled reports would have that set, but re-reading the OwnerId answer, turns out it is constant. My code turned out exactly as you suggested. Thanks! – Joshua Dance Sep 4 '14 at 20:30

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.