I have a 65 multi step wizard form where i need to collect data on each step and have a previous and next button on each page. I have to store the data on each page and finally at the end store all the data. I could use one controller for all 65 pages to get the view state but the code would become too large and unwieldy.

I was thinking of using 4 custom controllers and having each controller pass data from several pages to another controller. Now the question is how can I pass the entire view state from one controller to another controller?

  • Can you clarify what is happening on the forms a bit? When someone hits previous or next why can't you just save their responses to the database and then pass in the id or ids of the records to the next step. Feb 15, 2013 at 0:20
  • @grigriforce I can store the values on each step. My issue is the controller will become too big with 70 forms have 70 postback methods on the controller. I would like to split multiple controllers from maintenance perspective. Feb 15, 2013 at 3:50

2 Answers 2


If you can save the users response to salesforce when they hit previous/next and they are just reloading the same visualforce page over and over you can use the PageReference.SetRedirect method to flush the view state to avoid running into any issues from storing the entire state from 70 steps.

So your controller logic would be:

//constructor queries salesforce to get users responses from previous step(s)

public Pagereference Next()
    //save users responses    

    PageReference pageRef = Page.ThisVFPage;
    return pageRef;

A few options.

If your controller state variables are all pretty much needed across the entire massive flow, keep all your postback methods in one controller, but delegate their implementation to other classes that manage the logic. Example:

public PageReference step9() {
    return Step9Controller.go(param1, param2, ...); // this is a static method on some delegated class

If your shared state only needs to pass a few variables from controller to controller, divide your controllers at the points where shared state is minimal, and pass as query parameters:

public PageReference step9() {
    // do your implementation here
    return new PageReference('/Step10?p1=' + param1 + '&p2=' + param2); // this page is backed by the next controller

If neither of those options is attractive (maybe you don't have that much shared state, but you also don't want to expose the variables to the user), you can save the state to a table row and pass that ID to the next controller:

public PageReference step9() {
    // do your implementation here
    Wizard_State__c next = Wizard_State__c(Param1__c = param1, Param2__c = param2); // or whatever you need
    insert next;
    return new PageReference('/Step10?nextId=' + next.Id); // this page is backed by the next controller

There are a few other ways to handle it too, but those are the ones I'd opt for.

  • I like your approach and we are going with your approach as a solution. Feb 15, 2013 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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