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
tlsarna1tlsarna1 

Carry Variable Across Multiple Wizard Pages

So ... when I went to training about 6 months ago, they told me to make sure I set myself up for "little successes".  Now, I know why ... because I have already run into a stickler on my first piece of code that is beyond frustrating!!

 

I've created a custom object, a controller extension and two VF pages, which will serve as the beginning of a wizard.  I want to be able to choose the Account Name in the first page of the wizard, and then have that Account Name and the corresponding Global Region (custom) field from the Account object display on the 2nd page of the wizard.   But no matter what I do I can't get the Account name to move from page 1 to page 2. 

 

Here's the code I have so far ... I'm sure it's something simple ...

 

Thanks in advance for your help!!  I'm going to post this in both the VF discussion forum and the Apex one, just in case ....

 

Controller Extension:

public with sharing class ARWizard {

// First declare all properties that will be used to maintain the state of the wizard.
// Search results are not transient in case the user accidentally selects the wrong one and wants to go back.
    
// First property is the standard controller, called controller,
// so that in read mode it will work as object is built.
     public ApexPages.standardController controller {get; set;}
     
// Next is an Assistance Request variable called assistanceRequest to insert when we're done
    public Assistance_Request__c assistanceRequest { get; set; }
     
// Next property is the Account, referenced by the variable called account with default getter/setter
    public Account account {get;set;}
    
// Next property is the Account ID called "accountId" with default getter/setter
    public ID accountID {get;set;}
    
// Now I have to build a constructor to create the Assistance Request 
    public ARWizard (ApexPages.standardController controller) {
      
  }   
  

// The next 2 methods control navigation through the wizard. 
// Each returns a PageReference for one of the 2 pages in the wizard.
// Note that the redirect attribute does not need to be set on the PageReference 
// because the URL does not need to change when users move from page to page.

// First is a method called "step1" to return the page reference for the ARStep1 page
    public PageReference step1() {
        return Page.arStep1;
    }

// Next is a method called "step2" to get the account and then return the page reference for the ARStep2 page
     public PageReference step2() {
        try {
        	account = [SELECT Id,Name,Global_Region__c
        	           FROM Account
        	           WHERE Id =: assistanceRequest.Account_Name__c];
           }
        catch(Exception e)  {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage()));
    }
    return Page.arStep2;
     }


       public PageReference save() {
      	     	System.debug('&&&&&&& Account=' + account);
        	try{
        		insert assistanceRequest;
        	} catch (System.DmlException e) {
				ApexPages.addMessages(e);
				return null;
    		}
        	controller = new ApexPages.standardController(assistanceRequest);
        	return controller.view();
        }
}

 

Page 1:

<apex:page standardController="Assistance_Request__c" extensions="ARWizard" tabStyle="Assistance_Request__c">
  
    <script>
    function confirmCancel(){
    var isCancel = confirm("Are you sure you wish to cancel and exit this Assistance Request?");
    if (isCancel) return true;
    return false;
    }
    </script>
    
    <apex:sectionHeader title="Assistance Request" subtitle="Step 1 of X"/>
  <apex:form > 
      <apex:pageBlock id="theBlock" title="Assistance Request Creation" mode="edit">
          <apex:pageBlockButtons >
              <apex:commandButton action="{!step2}" value="Next"/>
              <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" style="margin-left: 2em"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection title="Account Information" columns="1">
              <apex:inputField value="{!AssistanceRequest.Account_Name__c}"/>
          </apex:pageBlockSection>
      </apex:pageBlock> 
  </apex:form>
</apex:page>

 

Page 2:

<apex:page standardController="Assistance_Request__c" extensions="ARWizard" tabStyle="Assistance_Request__c">
  
        <script>
    function confirmCancel(){
    var isCancel = confirm("Are you sure you wish to cancel and exit this Assistance Request?");
    if (isCancel) return true;
    return false;
    }
    </script>
    
    <apex:sectionHeader title="Assistance Request" subtitle="Step 2 of X"/>
    
  <apex:form > 
      <apex:pageBlock id="theBlock" title="Assistance Request Creation - Request Details" mode="edit">
          <apex:pageBlockButtons >
              <apex:commandButton action="{!step1}" value="Previous"/>
              <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" style="margin-left: 2em"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection title="Account Information" columns="2">
              <apex:outputField value="{!Assistance_Request__c.Account_Name__c}"/>
              <apex:outputField value="{!Assistance_Request__c.Global_Region__c}"/>
          </apex:pageBlockSection>
          
           <apex:pageBlockSection title="Request Information" columns="2">
              This is where the request product, category and action will go.
          </apex:pageBlockSection>
      </apex:pageBlock> 
  </apex:form>
</apex:page>

 

pat!pat!

Is the Account_Name__c in your custom object was a lookup field related to Account object ? And I beleive that Global_Region__c was a custom field in Account object.

If yes, try to use the account which has the result from your SOQL

account = [SELECT Id,Name,Global_Region__c
                   FROM Account
                   WHERE Id =: assistanceRequest.Account_Name__c];

 and do this in page 2

<apex:pageBlockSection title="Account Information" columns="2">
   <apex:outputField value="{!account.Name}"/>
   <apex:outputField value="{!account.Global_Region__c}"/​>
</apex:pageBlockSection>

 instead of

 <apex:pageBlockSection title="Account Information" columns="2">
              <apex:outputField value="{!Assistance_Request__c.Account_Name__c}"/>
              <apex:outputField value="{!Assistance_Request__c.Global_Region__c}"/​>
          </apex:pageBlockSection>

 first, make sure that your SOQL returns a exactly 1 value you can check it in the System Log. Open your system log while running the process.. Hope it works.

Goodluck! :)

Pat