6

I am trying to query all the standard reports using folder object in salesforce. I am able to collect all the attributes except Folder Name.

I am using the same query to retrieve the custom folder names which I could make it. But it does not works for the standard folders.

Following is the query which I am using.

listFolders=[Select Id, Name, AccessType, Type, IsReadOnly, DeveloperName 
             From Folder 
             Where Type = 'Report']; 
3

I'm afraid you'll need 2 queries to achieve that.

Report folders are funny, check how is the report owner set?

The relationship between Folder and Report is visible when you run describes but it has no name so it can't be used.

You can't go "up"

SELECT Id, Name, OwnerId, Owner.Name
FROM Report

And you can't go "down"

SELECT Id, Name, DeveloperName,
    (SELECT Id, Name, DeveloperName FROM Reports)
FROM Folder

Because of that I don't think even participating in the pilot "polymorphic SOQL" thingie will help you...


Build a Map<Id, Folder> = new Map<Id, Folder>([your original query here]) and manually match with result of one of these

// 1
SELECT Id, Name, OwnerId
FROM Report
WHERE OwnerId IN :yourMap.keyset()
// or 
// WHERE OwnerId IN (SELECT Id FROM Folder WHERE Type = 'Report')

// 2 - should give same results
SELECT Id, Name, OwnerId, Owner.Name
FROM Report
WHERE OwnerId != :UserInfo.getUserId() AND OwnerId != :UserInfo.getOrganizationId()
  • Hi, Thanks @eyescream for the response. I think, I would asked the question slightly in a different way. Question:I need to query all the report FOLDERs with their DeveloperName. I am able to achieve the same for Custom Folders, but not for Standard Folders. Hope you may clear now. – I.S.K Jun 6 '13 at 12:01
  • Uh, no idea then. Dev. Name will be blank, all reports there are special (don't have Ids but long weird URLs), you also can't save new reports to these... – eyescream Jun 6 '13 at 12:38

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.