function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mustafatop10mustafatop10 

How to I get reports by specific folder using soql?

How can I make a query similar to following:

Report r = [SELECT id,name FROM Report WHERE foldername='myfolder' LIMIT 1];

Unfortunately, the report object doesn't contain field that is like 'foldername' 
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_report.htm

Yoganand GadekarYoganand Gadekar

Try following,

You will get all the reports in your folder named  'MyFolder'

 

List<Report> ReportList;

Id myFolderId = [select id from folder where developername = 'MyFolder' limit 1].id;
if(myFolderId != null)
ReportList = [select id, name, description from report where ownerid = : myFolderid];
 
System.debug('**List of Reports in MyFolder**'+ReportList );

 

Hit kudos and Mark this as answer if it helps you so that others can benifit from this.

 

Thanks,

Yoganand.

David HalesDavid Hales
Hi mustafatop10 
 using this :
SELECT id, name FROM Report WHERE ownerId IN (
    SELECT ID FROM Folder WHERE developerName = 'FolderName'
)

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

If the above suggestion worked, let us know by marking the answer as "Best Answer" right under the comment which will help the rest of the community should they have a similar issue in the future. 

Thanks & Regards 
David Hales(1044)
Kloudrac Software Pvt. Ltd.