I am working on a Visualforce page that will call our internal report server with a few parameters from the page to run a report. However the URL I am calling has a secondary path after the initial page path. I can not seem to get page reference to work as it only sees the page and allows for parameters but not the secondary path.

The URL I call looks like this:


Above, %2fTest%2fInitiatives%2fUsage%2fSI+Usage+at+District+Level is the secondary path. How can I pass this page reference back to redirect to the URL knowing I can send variables for the dates and ID?

Is there any other way to redirect to the URL and pass the parameters needed? I tried JavaScript but it redirects before the controller is called to return the parameters.

  • Can you please post some of what you have tried so far? I am having a difficult time fulling understanding what you are asking for. – techbusinessman Jul 22 '15 at 20:04
  • From a command button on the page I would like to redirect to an external URL. This URL contains parameters I would like to pass with values from the controller. I have a problem using a pagereference so I am also looking at other ways to accomplish this. – James Allen Jul 23 '15 at 20:22
  • You could always go the ugly route and hand-construct the URL as a text string and concat it with your field values. Since your URL has a secondary path it may be that the PageReference class doesn't support that. – akarnid Jan 21 '16 at 15:11
  • The problem appears to be that your "path" parameter literally is no url parameter at all. It's just some string that is part of query string, which makes this a poorly designed URL pattern, imho. The solution (in js!) very much depends on what you mean by " call our internal report server". Do you mean redirect? Do you want to embed something? – tobibeer Feb 24 '16 at 10:34

You want to do something similar to the following:

PageReference page = new PageReference('http://reports/ReportServer/Pages/ReportViewer.aspx?%2fTest%2fInitiatives%2fUsage%2fSI+Usage+at+District+Level');
page.getParameters().put('rs:Command', 'Render');
page.getParameters().put('rc:Parameters', 'false');
page.getParameters().put('rc:Toolbar', 'false');
page.getParameters().put('startDate', '5/1/2015');
page.getParameters().put('endDate', '6/1/2015');
page.getParameters().put('districtID', '3970');
return page;
| improve this answer | |
  • That is basically what I have been trying to do. But it does not navigate past the .aspx page reference. When debugging the pagereference variable it only contains the path up to the .aspx. – James Allen Jul 25 '15 at 15:54

As it appears little tough to accomplish by controller and Pagereference I will suggest using Javascript. The problem of not getting controller values in url can be solved by below approach:

Define a outputpanel like this on top of your visualforce page:

<apex:outputpanel id="panelToRefresh" >

        var reportPageURL='http://reports/ReportServer/Pages/ReportViewer.aspx?%2fTest%2fInitiatives%2fUsage%2fSI+Usage+at+District+Level&rs:Command=Render&rc:Parameters=false&rc:Toolbar={!variableFromConroller1}&startDate={!variableFromConroller2}&endDate={!variableFromConroller3}&districtID={!variableFromConroller4}';

 fuction redirectToReport(){

Note that we are binding controller parameters in the url.

Now change your command button code to below:

<apex:commandbutton action="{!methodWhichYouWereCalling}" rerender="panelToRefresh" onComplete="redirectToReport();" />

This will make things work for you. Here is explanation how :

  1. Hitting your commandbutton will call same Controller function as you were calling earlier.Controller function will do the job of setting parameters of report url and will assign them to some variables accessible by visualforce page.
  2. Rerender will assign refreshed values to report parameter.
  3. Oncomplete function of commandbutton will redirect to report with all parametrs set properly.
| improve this answer | |

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.