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
Jonathan WallaceJonathan Wallace 

change what reports get opened from a button without recoding a button

we currently have a button that opens a static list of reports, what i would like to do is have a "location" be static, and be able to change what report is in that location without having to recode the button everytime. Any ideas? 
Chris  ByromChris Byrom
You can put all the reports in a specific folder, and then query for all the reports in the folder.

https://developer.salesforce.com/forums/?id=906F00000008zEMIAY 
Jonathan WallaceJonathan Wallace
could i do  this query on the fly? or should it go in an apex class? 
Chris  ByromChris Byrom
I would just put it in an apex controller, and use it to populate the page whenever it is loaded.
Jonathan WallaceJonathan Wallace
this code doesn't make sense to me, where would i specify the report folder name for my org?
 
folder[] ff = [select id from folder where developername = 'my report folder name?'];
id fid = (ff.isEmpty()) ? null : ff[0].id;
report[] rpts = [select id, name, description from report where ownerid = : fid and ownerid != null order by name];
return (rpts.isEmpty() == null) ? null : rpts;

i'm still learning how apex controllers work, this one is a little confusing to me. Thanks for your help!
Chris  ByromChris Byrom
Wow, I swore I added another answer to this yesterday. Weird. I simplified the code and put it in a simple controller and page. The notation above is a little hard to understand when you first start.

Controller
public class ReportPageController {
    public List<Report> reportList {get;set;}

    public ReportPageController(){
        List<Folder> folders = [Select Id from Folder Where developername = 'Test_Report']; 
		List<Report> reports = new List<Report>();
		if(!folders.isEmpty()){ 
			reports = [Select Id, Name, Description from report where OwnerId =: folders[0].Id];
		}
		this.reportList = reports;
	}
}

Page
<apex:page controller="ReportPageController">
    <apex:repeat value="{!reportList}" var="report">
        {!report.Name}
    </apex:repeat>    
</apex:page>

Hope this helps.