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
BrianWKBrianWK 

setRedirect(false) doesn't redirect page, but setRedirect(true) does

Hello everyone. I have to Visualforce pages. In certain scenario I want VFPage1 to auto-redirect to VFPage2. I have the logic working and the redirect does work, but only when set to true.

 

I don't want to flush the view state. Both pages are using the same controller, so I should be able to use redirect false.

 

Instead what happens is the page loads to VFPage1. however, if I change redirect to true, and open the exact same page-- the auto-redirect works and takes me to Step2.

 

Any ideas and what might be happening?

 

I actually had a different problem using the same code setup and you can find a snippet of that here: http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=17960

 

Basically I have apex page call an Action that returns the Page Reference. I've confirmed that the page reference does return successfully in the debug regardless if the redirect is set to True or False. But the page only actually redirects when set to true.

prageethprageeth

Hello 

I am not verymuch clear about your current problem.  I followed the link you supplied.

The reason for that problem is the constructor can't return anything. Therefore your pagereference for second page is actually not returned.

 

 

public S7_Status_Controller_Extension(){

Initialize(); //This can call another method but can't return the resulting value

} 

 

So use the action attribute in <apex page tag.

 

<apex:page Controller="S7_Status_Controller_Extension" action="{!initialize}"> 

BrianWKBrianWK

Prageeth -- sorry for the confusion, but the issue in the linked post was resolved. I have the Apex Page calling a PageReference that either returns NUll or The next Page to redirect.

 

As I said -- this works as long as the PageReference as setRedirect to true. If it's false it doesn't work.

 

That's the issue currently. The redirection works perfectly fine as long as I have it WizardStep2.setRedirect(true). This returns the PageReference and successfully redirects the browser to that page. If that's set to false it acts as if the method return null.

 

I would expect WizardStep2.setRedirect(false) to return the PageReference (debug says it does) and redirect the browser to that page without resetting the view state. This expected behavior does not occur. Instead I get the exact same result as if the method returned null --- but the debug code shows the same PageReference being returned.

narendharnarendhar

Hi

I am also facing the same problem, kindly let me know the solution.


BrianWK wrote:

Prageeth -- sorry for the confusion, but the issue in the linked post was resolved. I have the Apex Page calling a PageReference that either returns NUll or The next Page to redirect.

 

As I said -- this works as long as the PageReference as setRedirect to true. If it's false it doesn't work.

 

That's the issue currently. The redirection works perfectly fine as long as I have it WizardStep2.setRedirect(true). This returns the PageReference and successfully redirects the browser to that page. If that's set to false it acts as if the method return null.

 

I would expect WizardStep2.setRedirect(false) to return the PageReference (debug says it does) and redirect the browser to that page without resetting the view state. This expected behavior does not occur. Instead I get the exact same result as if the method returned null --- but the debug code shows the same PageReference being returned.