[SalesForce] How to pass session state between multiple custom controllers

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?

Best Answer

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;
    pageRef.getParameters().put('id',userResponses.ID);
    pageRef.setRedirect(true);
    return pageRef;
}