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
TehNrdTehNrd 

How to create a branching wizard?

So we have a custom object in salesforce.com that allows us to build pretty complex product configurations and I would like to create a wizard for this. Straight through wizards are no problem, but what I want to do is create a dynamic wizard to show specific pages based on values selected.

The first page only contains one picklist with a list of our products. Based on what is selected here I would like to forward to a specific page.

Page one:
Picklist values: Product A, Product B, Product C.

If A selected, go to apex page A, if B selected go to apex page B, etc, I struggle with setting up the controller class and handling these if statements.

I would think it would be pretty simple I just struggle with the syntax and code form. You can see what I am trying to do with the branch function.



Here is what I have

Page 1
Code:
<apex:page controller="configGuide" tabStyle="Configuration__c">
<apex:sectionHeader title="Configuation Wizard" subtitle="Step 1"/>
<apex:form>
<apex:pageBlock title="Configuration Type">

<apex:pageBlockButtons>
<apex:commandButton action="{!branch}" value="Next"/>
</apex:pageBlockButtons>

<apex:pageBlockSection>




<apex:panelGrid>
<apex:outputLabel value="What Type of configuration would you like to build—" for="configType"/>
<apex:inputField id="configType" value="{!config.Product__c}"/>

</apex:panelGrid>


</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

 Controller
Code:
public class configGuide {

Configuration__c config;

public Configuration__c getConfig() {
if(config == null) config = new Configuration__c();
return config;
}

public PageReference branch() {
if(config.Product__c == 'BIG-IP'){
 return Page.BIGStep1;
}
} public PageReference configStep1() { return Page.configStep1; } public PageReference FPStep1() { return Page.FPStep1; } public PageReference BigStep1() { return Page.BigStep1; } public PageReference WJStep1() { return Page.WJStep1; } public PageReference save() { insert config; PageReference configPage = new PageReference('/' + config.id); configPage.setRedirect(true); return configPage; } }

 


RickyGRickyG
What part of the syntax are you having a problem with?  I think you would have to use ISPICKVAL to see which value was picked with the picklist.  And an apex:SelectList tag with a size=1 attribute to make the pick list.

Hope this helps.
mtbclimbermtbclimber
Are you not getting redirected to 'Page.BIGStep1' when you click the button with a value of 'BIG-IP' in the picklist? (BTW you do not need to use ISPICKVAL to evaluate picklists in Apex.)

Does Page.BIGStep1 use the configGuide controller?
TehNrdTehNrd
Correct, it is not going to the BIGStep1 page. Infact it isn't even saving, I should have mentioned that, sorry about that.  I have setup the BIGStep1 page to use the configGuide controller.

So when the next button is clicked it is calling the branch() method and this is where I need assistance. I am hoping that it can do some simple logic that says if Config.Product__c value is BIG-IP go to BIGStep1, if FirePass go to FPStep1 etc.

Here are some other things I have tried for the branch method trying to get it to work. The error I get for the first two is : Error: Compile Error: Non-void method might not return a value at line 12 column 13, which is the first line inside the branch() method. In the last example it says the getConfig method does not exist.

Code:
public PageReference branch() {
Configuration__c config = getConfig();
if(config.Product__c == 'BIG-IP'){
return Page.BIGStep1;
}
}


public PageReference branch() {
Configuration__c config = getConfig();
if(config.Product__c == 'BIG-IP'){
return BIGStep1();
}
}

public static void branch() {
Configuration__c config = configGuide.getConfig();
if(config.Product__c == 'BIG-IP'){
return BIGStep1();
}
}

 Thanks for the help on this.




Message Edited by TehNrd on 12-11-2007 09:46 AM
thedgethedge
The reason the first two are giving you an error is because the return is buried inside of your if statement.  So if config.Product__c does not equal 'BIG-IP' then no value is returned from your function.  As defined these functions should return a PageReference.   So....this....
 
public PageReference branch() {
Configuration__c config = getConfig();
if(config.Product__c == 'BIG-IP'){
return Page.BIGStep1;
}
}

should be......
 
public PageReference branch() {
       // create a PageReference variable that contains the default next page.
      PageReference p=Page.defaultPage; 

      Configuration__c config = getConfig();
      if(config.Product__c == 'BIG-IP'){
             p=Page.BIGStep1;
      }
return p;
}
 
In the third example...you should be able to call the getConfig() function without the preceeding reference to the controller name since this funciton is defined locally.
 
hope this helps.

Message Edited by thedge on 12-14-2007 08:20 PM


Message Edited by thedge on 12-14-2007 08:25 PM
TehNrdTehNrd
Thanks for the help, that did the trick!

At first I copy and pasted and it didnt work but then I typed it out and all is good. I thing the web editor is a little finicky, can't wait for the next toolkit that support VF pages.
dchasmandchasman
We are already hard at work on the next version of Developer Mode that will address a number of issues (e.g. pasting from a rich text source flakyness, error location highlighting, hyper navigation, better tab handling, additional/smarter autosuggest, many new quick fixers/refactorings) - many of these features will only be available via the on demand dev environment so please don't dismiss the web environment too quickly :-)
TehNrdTehNrd
Sounds great. I'm looking forward to it.

Jason