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
cgosscgoss 

Can I package links to reports?

I'd like to add a link to a custom report that's included in our managed package to a visualforce page (also packaged) but I'm hesitant to do so because it just uses a hard-coded ID link. I've seem to recall reading something way back when that report IDs were automatically swapped out upon package installation for object links, but I'm doubtful that will be the case for visualforce pages.


It would be ideal if this idea were delivered:

https://sites.secure.force.com/success/ideaView?id=08730000000bRreAAE

 

Does anyone have any experience linking to packaged reports?

 

Thanks,

Chuck

Best Answer chosen by Admin (Salesforce Developers) 
zachelrathzachelrath

Chuck,

 

In my experience, the only way to achieve this is to use a Visualforce page that serves up Reports by Name. Check out my blog post on the idea:

 

Linking to Reports in Managed Packages

 

Regards,

 

Zach McElrath

Skoodat LLC
@zachelrath 

All Answers

zachelrathzachelrath

Chuck,

 

In my experience, the only way to achieve this is to use a Visualforce page that serves up Reports by Name. Check out my blog post on the idea:

 

Linking to Reports in Managed Packages

 

Regards,

 

Zach McElrath

Skoodat LLC
@zachelrath 

This was selected as the best answer
cgosscgoss

Very nice solution! In my case, I'm linking to the report from a VF page, so I'll tweak the controller a bit to be able to work when called from another controller, and not just the redirect page.

 

If you'd like, I can send you the code if you want to update your blog post...

zachelrathzachelrath

Thanks! Glad to hear it was helpful.

 

As far as using this code from another controller, there's lots of different scenarios and ways it could be done, so I probably won't modify the blog post. For instance, if I just added the following line:

 

public ViewReportController(ApexPages.StandardController sdtctl) {}

 

then this controller could be used as an Extension to a standard controller. Or, you could have it be an extension to a custom controller. For instance, if the custom controller was called "MyCustomController.cls", then if you added

 

public ViewReportController(MyCustomController ctl) {}

 

then you could use ViewReportCOntroller as an extension controller to your Custom Controller, e.g. you could have a VF page like so:

 

<apex:page controller="MyCustomController" extensions="ViewReportController">

 

And of course the easiest change that I could make would be to make a static version of the Redirect method, so that you could do the following within your custom controller:

 

PageReference result = ViewReportController.Redirect('My_Report_Name','myNamespace');

return result;

 

But here, again, there are possibilities for variation, depending on your use case, as some people who are passing lots of dynamic parameters would probably want to send in a Map<String,String> of parameter values, e.g.

 

Map<String,String> reportParams = new Map<String,String>{

'dn' => 'My_Report_Name',

'ns => 'My_Namespace',

'pv0' => 'Lincoln+High+School',

pv1' => 'Active'

// etc., etc.

};

PageReference result = ViewReportController.Redirect(reportParams);

return result;