[SalesForce] using window.open to a visual force page in a new window strips parameters from old page

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?

Best Answer

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}';

Related Topic