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;
}
The two controllers that are available to you are:
- StandardController
- StandardSetController
StandardController
From the docs: A Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated Visualforce markup, such as when a user clicks a button or link. Controllers also provide access to the data that should be displayed in a page, and can modify component behavior.
You can find more information here, but basically a StandardController
is for ONE record, i.e. if you'd like to create a new Visualforce page for a single record, you'd use a Standard Controller in your Apex. For example:
public with sharing class MyController {
private ApexPages.StandardController controller;
public MyController(ApexPages.StandardController controller) {
this.controller = controller;
}
// maybe this gets called from a button within your VF page
public void doSomethingWithSingleRecord() {
SObject record = controller.getRecord();
record.put('Status__c', true);
update record;
}
}
StandardSetController
From the docs: Standard list controllers allow you to create Visualforce pages that can display or act on a set of records. Examples of existing Salesforce pages that work with a set of records include list pages, related lists, and mass action pages.
You can find more information here, but basically Set (list) controllers are for MULTIPLE (or a list of) records, i.e. if you'd like to create a new Visualforce page for a List of records (or even from a selection of records on a List view), you'd use a Standard Set Controller in your Apex. For example:
public with sharing class MyController {
private ApexPages.StandardSetController setController;
public MyController(ApexPages.StandardSetController setController) {
this.setController = setController;
}
//maybe this gets called from a button on your list view
public void doSomethingWithMultipleRecords() {
List<SObject> records = setController.getSelected();
for(SObject record : records) {
record.put('Status__c', true);
}
update records;
}
}
Best Answer
In the context of visualforce, to take advantage of the built-in features of Visualforce to access your org's data, you must use a controller. All controllers are Apex classes, either standard Apex classes (ApexPages.StandardController or ApexPages.StandardSetController) or your own custom Apex class. You can also extend functionality of any of these with an Extension class.
I tend to be a bit picky with my terminology here. Controllers are controllers. Extensions are not controllers. And for me, the difference is that extensions cannot live by themselves on a page. In other words, I'm not permitted to use extensions, unless my page has a controller in the first place.
Another distinguishing feature is that a page is allowed only one controller ever. But I can add as many extensions as I need.
So let me begin (what has become a dissertation) with controllers:
Controllers are attached to your page using one of three mutually exclusive formats, standard controller, standard list/set controller, custom controller.
For a page with a single record, accessing standard data and behavior of your object you would use standard controller:
If you want a page with many records, using standard list view, and list actions you could use standard list controller:
If you want to use completely custom functionality and don't really need most of the standard object behaviors, custom controller is a good option, but bear in mind, any standard actions you want to use will have to be implemented in your custom class. A page with a custom controller would use the following attribute:
But bear in mind, you yourself can instantiate ApexPages.StandardController to use its features and functionality. I often use the pattern below to instantiate standard controller to get access to its methods:
The above instantiates Standard Controller privately, but then surfaces a public save method that is just a pass-through of the controller's save method. The constructor does the housekeeping of creating the actual record I'm working with.
If I want to add to the functionality of any controller, I can then use an extension. Extensions work with either standard or custom controllers. Standard controller with custom extension, for me, is the most common construct I use for Visualforce that will operate inside my org. I get all the power of the standard controller, but all the flexibility of Apex. The syntax for an extension with a standard controller page would be as follows:
The extension class is then required to implement a constructor that accepts the type of the controller. You will then typically want to get a handle to the standard controller instance that is floating around, and the sObject instance that it represents. So for a standard controller page:
With a custom controller and extension, you can probably extrapolate from the above, but just to close the loop.
Again, the extension class implements a constructor that accepts the type of the controller, only now it is my custom class. From there, apart from getting a local handle to your custom controller instance, there isn't a pattern, per-se, but the local handle allows you to interact directly with your custom controller, in whatever way necessary, of course. :
There are additional tricks that are very powerful, such as instantiating ApexPages.StandardSetController in your class to take advantage of that class' built-in paging, features. For more on that, there is a great video from Dreamforce 11 that shows how this can work: http://youtu.be/Js00YUpJAjs