Monday 25 November 2013

How to Build A Wizard in Salesforce

Hi Folks,
After getting so many discussion threads over the same topic. I came up with solution of the problem.
Problems:
Type1: Facing issues of passing values to Controller while redirecting to other page when controller is common.
Type2: Either value get passed properly without successful redirection or successful redirection without successful passing value to controller.
Here is the Code snippets:

Page1 : In this page we are trying to pass parameters from page to controller through two ways one is as hidden variable & other one is publicly exposed property

 
  
    
  
  
      
        
       
                
          Exposed Value:          
          

      
             
  

Page2 :



        
      
      
          Hidden Value: 
          
Exposed Value: 
          
 
      
  

Common Controller:
/*
* Author : Sandeep Singhal
* Purpose : This class is common controller between both pages
*/
public Class CommonController{

    // Constructor
    public CommonController()
    {
        
    }
    // Public Properties
    public String valueHoldertExt{get;set;}
    public String valueHolderHidden{get;set;}
    
    // To go to next page mantaining values of controller
    public pageReference goToNextPage()
    {
        PageReference pgRef =  new PageReference('/apex/Screen2');
        return pgRef ;
    }
    
    // To go to Previous page mantaining values of controller
    public pageReference goToPreviousPage()
    {
        PageReference pgRef =  new PageReference('/apex/Screen1');
        return pgRef ;
    }
}
So let's test the functionality:
From page 1, I am passing a hidden value 'sandeep' (refer code of page1) & 'Test1' in inputText field & click on 'Next Page' button. After clicking on'Next Page' button on page1 gets redirected to page2 but values are maintained.(Note: URL is not getting changed. This is a property of salesforce redirection in wizard).)

Here is Page2 if we change value in input text & click on 'Previous Page' button this new value will be available on Page1.
                                           
Here we can setup a complete wizard.