function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Visualforce Wizard Issues

I'm fairly new to Visualforce but a long-time user of SFDC. I am trying to create a simple wizard to walk users through 5 pages of one form instead of one long form per the usual SFDC UI. I am running into a major issue:

I have a number of validations set-up and beyond requiring certain fields, I have no idea how to prevent the user from continuing to the next page if there are validation issues. This is an issue since the whole process crashes if the user saves the record without fixing the issues.

I tried to copy as much from the example in the Cookbook but I've hit a wall.

Here is my code (substitute x for < due to posting issues):

Page 1 of 5 (all of the VF pages use the same logic/framework)

xapex: page standardController="Penrose_Project__c" extensions="PenroseProjectWizard" tabStyle="Penrose_Project__c">
xapex:sectionHeader title="New Project"
subtitle="Location - Step 1 of 5"/>
xapex:form >
xapex: pageBlock >

xapex: pageBlockButtons >
xapex:commandButton action="{!cancel}" value="Cancel"/>
xapex:commandButton action="{!step2}" value="Next"/>
x/apex: pageBlockButtons>

xapex: pageBlockSection columns="2" title="Location Information">
xapex: outputField value="{!PenProj.Name}"/>
xapex:inputField id="building" value="{!PenProj.P_Building__c}" required="TRUE"/>
xapex:inputField id="floor" value="{!PenProj.P_Floor__c}" required="TRUE"/>
x/apex: pageBlockSection>

xapex: pageBlockSection columns="2" title="Departments Affected">
xapex:inputField id="above" value="{!PenProj.Above__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="below" value="{!PenProj.Below__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="north" value="{!PenProj.North__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="south" value="{!PenProj.South__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="east" value="{!PenProj.East__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="west" value="{!PenProj.West__c}" required="TRUE"/ style="width:300px">
x/apex: pageBlockSection>

xapex: pageBlockSection columns="2" title="Project Dates">
xapex:inputField id="start" value="{!PenProj.Project_Start_Date__c}" required="TRUE"/>
xapex:inputField id="end" value="{!PenProj.Project_End_Date__c}" required="TRUE"/>
x/apex: pageBlockSection>

x/apex: pageBlock>
x/apex: page>


public class PenroseProjectWizard {

Account account;
Penrose_Project__c PenProj;

public Penrose_Project__c getPenProj(){
if(PenProj == null) PenProj = new Penrose_Project__c();
return PenProj;

public PenroseProjectWizard(ApexPages.StandardController stdController){
PenProj = (Penrose_Project__c) stdController.getRecord();
PenProj.Location__c = ApexPages.currentPage().getParameters().get('location');
PenProj.Name = ApexPages.currentPage().getParameters().get('name');
PenProj.RecordTypeId = [SELECT r.Id FROM RecordType r WHERE r.SobjectType = 'Penrose_Project__c' AND r.Name = :ApexPages.currentPage().getParameters().get('recordtype')].Id;

public PageReference cancel() {
PageReference Cancelled = new PageReference('/' + PenProj.Location__c);
return Cancelled;
public PageReference step1() {
return Page.newphproject1;
public PageReference step2() {
return Page.newphproject2;
public PageReference step3() {
return Page.newphproject3;
public PageReference step4() {
return Page.newphproject4;
public PageReference step5() {
return Page.newphproject5;
public PageReference save() {
insert PenProj;

PageReference ProjectStep = new PageReference('/' +;
return ProjectStep;

Custom Button:

Any help, tips or tricks would be greatly appreciated.


Message Edited by pacstrats on 11-14-2008 12:49 AM

Message Edited by pacstrats on 11-14-2008 12:49 AM

Message Edited by pacstrats on 11-14-2008 12:50 AM

Message Edited by pacstrats on 11-14-2008 12:54 AM

Message Edited by pacstrats on 11-14-2008 12:56 AM
David VPDavid VP
Did you try using the immediate=true attribute in your commandbuttons ? That should bypass validation.


Message Edited by David VP on 11-14-2008 08:48 PM
No, but I think I found the solution by using actionRegion, see below:

*apex:actionRegion >
*apex: pageBlockSection title="Noise" columns="1">
*apex: pageBlockSectionItem >
*apex: outputLabel value="Noise Generated?"/>
*apex: outputPanel >
*apex:inputField id="noise" value="{!PenProj.Noise_Generated__c}" required="true">
*apex:actionSupport event="onchange" rerender="step3"
*apex:actionStatus startText="applying value..." id="noise"/>
*/apex: outputPanel>
*/apex: pageBlockSectionItem>
*/apex: pageBlockSection>

*apex: pageBlockSection columns="2"
rendered="{!PenProj.Noise_Generated__c == 'Yes'}">
*apex:inputField id="who_noise" value="{!PenProj.Who_Contacted_Noise__c}"/ required="true">
*apex:inputField id="when_noise" value="{!PenProj.When_Contacted_Noise__c}"/ required="true">
*/apex: pageBlockSection>
David VPDavid VP
I would have to think about that : Actionregion is not meant to solve validation errors.

but if it works ...


P.S. Use the SRC button to insert code in your posts, it will make it a lot more readable. Happy coding !
Thanks for the tip.

This really didn't solve the validation issue but rather forces the user to complete the form as intended, which is what the validation code was ultimately used for.

That's actually a pretty good example of when you'd want to use actionRegion.  If you want to limit the scope of what you're submitting during an actionSupport call, actionRegion is a good way to go about it and will prevent you from running any unnecessary setters or very low level validations (think requiredness) when all you're trying to do is update a small portion of your page.

As far as your validation issues go, the problem is that most field validations happen at the API level on update or insert, and those validations aren't going to happen until you actually attempt to save the object, which usually happens in your last step.  So that means you might need to do your own validation in your controller -- check for invalid values in your fields and add an error message to your page so you don't continue on to step 2 if there's an error in step 1.
Assume that I have only one page - not multiple pages, so the issue of saving the object isn't there.

How do you display the validation error NEXT TO EACH FIELD - seems like all messages go to top of page when Apex:Messages or PageMessages tag is used. If I don't use the tag, no messages are shown.

I am using try/catch in my custom controller with ApexPages.addMessages(e) in catch exception.

If I don't catch the exception, I was hoping that validation rules will prevent a crash but the system crashes.