Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am following the book Visualforce Developer's Guide. There is one thing I am not quite clear with: when multiple VF pages are using one single controller - like in a wizard, how do VF decide when to create a new controller class instance and when will it use a previous one?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

According to visualforce guide > pageReference > setRedirect https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_PageReference_setRedirect.htm:

If setRedirect(false), the redirect is a server-side forward that preserves the view state if and only if the target page uses the same controller and contains the proper subset of extensions used by the source page.

In other words, if you want the controller to be reinstantiated (and hence the constructor reinvoked), in the pageReference method, use pgRef.setRedirect(true). The next page is loaded with the whole controller reinstantiated via its constructor.

But, if you don't want the controller class to be reinstantiated, use pgRef.setRedirect(false). the next page is loaded without re-construction.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.