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
NinoJoseNinoJose 

setRedirect(false) BUG on page 'action' attribute

All,

 

I create a sample POC in which an Interim Page (called Page 1) that will redirect to another Page (called Page 2) and uses the same controller when a condition met otherwise goes to another Page (called Page 3) when it does not meet the criteria. Page 3 does not use the same controller Page 1 & 2 uses.

 

I'm attaching the code here

 

Apex Controller

public class TestCntrl {
	public PageReference init(){
		PageReference pg  = null;
		if(true){
			pg = Page.TestPage2;
		}else{
			pg = Page.TestPage3;
		}
		return pg;
	}
}

 

Visual Force Page 1

<apex:page controller="TestCntrl" action="{!init}">
	<apex:form >
		Page 1
		<br/>
		<apex:commandButton value="page2" action="{!init}"/>
	</apex:form>
</apex:page>

 

Visual Force Page 2

<apex:page controller="TestCntrl">
Page 2
</apex:page>

 

Visual Force Page 3

<apex:page >
Page 3
</apex:page>

 

The thing is when the init() method is called in the action attribute of Page 1 it should redirect to Page 2 but it does not but if you look into the Debug logs it says it returning the correct PageReference. Also, if you click the button that calls the same method it redirects correctly. This is also true if you put setRedirect(false)  for Page 2 and setRedirect(true) for Page 3 (even though Page 3 does not need setRedirect since It does not use the same controller).

 

If you use setRedirect(true) for Page 2 it will work but it will loose the ViewState. I dont want to loose the ViewState and dont want to pass parameters for Page 2. According to the Visual Force documentation it should work but it seems like its not working. I have tested this already in 3 different Organization. I also search the forums and have removed the Developer mode but it still does not work!

 

I'm I missing something? Hope someone helps. TIA

 

AndrewAAndrewA

Has anyone solved this? I am having the same issue.