I use apex and visual force to create a list of customer cases. When they click on one it takes them to another VF page with a parameter in the url '?cn=00001234' this is used on the next page to retrieve the correct case number and show only specific details to the customer in a custom format. Works great but looks bad when printing. So I put a commandButton on the page that calls java script to open a new window with another visual force page designed for print layout. Also works great. But when we close the new window and are back on the detail view page the parameter '?cn=00001234' got stripped out of the old URL? I read the url with java to get the parameter to pass to the new page but nothing should be stripping the old parameter. Because the parameter is gone page refresh and the print view button won't work after the first time.

How do I prevent it from removing the parameters from the old url?

2 Answers 2


When performing a Visualforce action (commandButton, commandLink, etc.), a POST request is performed to Salesforce and your page state is updated. This POST request removes the original query parameters from the URL. What you will need to do is to capture that query parameter in your Apex controller using ApexPages.currentPage().getParameters().get('cn') and save it in an Apex variable. The apex variable is then preserved and can be accessed in your Visualforce page.

You may also find it easier to use a PageReference method to load the print view once you have the case number in Apex, but if you choose to stick with javascript you can still use Visualforce merge fields in javascript, i.e. var myVar = '{!myApexVar}';

  • I did the PageReference thing first and it works great but I need it to open in a new window because the print layout suppresses all salesforce parts so it looks good on the printed page. No sidebar etc. But you can't seem to open a new window with a PageReference return so I used java. Is there a way to trigger a java call without making the POST request on the old page?
    – Ohmicron
    Feb 11, 2016 at 15:11
  • By Java, I am guessing you mean JavaScript. If you want to open a link to a new window without touching the state of the current page, just use an HTML anchor (a) tag. Set the page url in the href attribute and set the target attribute to "_blank". This will tell the browser to open the link in a new window or tab without touching the current page. No JavaScript required.
    – dsharrison
    Feb 11, 2016 at 15:29

I got it to work. Any type of call using APEX caused a POST command like you said but instead of using APEX to generate a link or button I used straight html and the input tag and now it works without changing the original pages URL.

<input type="button" value="Print View" onClick="openNewVFPage();" />

The openNewVFPage is javascript that uses reads the current url gets the parameter creates the new 'myurl' with the parameter and calls the window.open('myurl','_blank');

Thanks for your help D.S.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .