+ Start a Discussion
ArpiArpi 

Retrieve a list of dashboard from a folder

Hello,

 

Is there a way to retrieve list of dashboards from a folder.The way reports can be retrieved using 

 

folder[] ff = [select id,name from folder where name = 'DOI BI Reports'];
id fid = (ff.isEmpty()) ? null : ff[0].id;
List<Report>  listReports = [select id, name from report where ownerid = : fid];

 

I do not want to use id directly as it chnages when we deploy to a new instance.

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
ArpiArpi

Well I got the solution it is title not name on dashboard.

 

 

Thanks Jeff

All Answers

Jeff MayJeff May

Dashboards work the same as Reports, and you don't have to hard-code the Id -- you can get it in your initial SOQL query.  

 

List<Folder> fs = [select Id, Name from Folder where Type = 'Dashboard' limit 1];

 

Then use the Dashboard.FolderId to find the Dashboards in whatever folder you want. 

 

for (Folder f : fs) {

 

    Dashboard d = [select Id, Name from Dashboard where FolderId :f.Id]; 

 

}

ArpiArpi

Thanks for answering the question when I try to use the below statement it gives me error in apex saying

 

"Error: Compile Error: No such column 'name' on entity 'Dashboard'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name."

 

List<Dashboard> d = [select Id,name from Dashboard where FolderId= :fs[0].Id]; 

ArpiArpi

Well I got the solution it is title not name on dashboard.

 

 

Thanks Jeff

This was selected as the best answer