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 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?

share|improve this question
    
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. –  Greg Grinberg Feb 15 '13 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. –  buyan kumar Feb 15 '13 at 3:50
add comment

2 Answers

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;
}
share|improve this answer
add comment

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.

share|improve this answer
    
I like your approach and we are going with your approach as a solution. –  buyan kumar Feb 15 '13 at 17:35
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.