You need to sign in to do that
Don't have an account?
Wizard Step 2 RELOAD is resetting the Properties/Variables.
Hello Folks,
I created a Visualforce wizard with 1 controller Class and 2 Visual Force pages.
Issue Description :
- If i open the WizardPage1.page and the Click Next button - my script Inserts a new account Record ,set a String property AccountId with the inserted Account's Id and redirect to WizardPage2 .
- Now on WizardPage2 if i reload(F5 / Mouse RightClick "Reload /")the page .It inserts another account record. whereas i am expecting the "AccountId" property to retain the First inserted account (Seems it is getting reset on reload of page)
- Then I added a "Back" button on WizardPage2 and tried follwoing
- Go to WizardPage1 Click Next - (Account Created) redirected to WizardPage2.
- Clicked "Back" on WizardPage2 and reached WizardPage1.
- From WizardPage1 again clicked Next and reached "WizardPage2.
- Now if i Reload the page Account is not getting created again and i can access value of property "AccountId".
Below is my controller and VF pages.
----------------------------------------------------------------------------------Class Start
public with sharing class customWizardcontroller {
public Account objAccount{get;set;}
public String AccountId {get;set;}
//Constructor
public customWizardcontroller()
{
try{
objAccount= new Account(Name = 'Wizard testing');
}
catch(Exception e) { //Handle Exception }
}
public Pagereference goNextStep()
{
try{ if (AccountId == null || AccountId == '')
{ insert objAccount; AccountId = objAccount.Id; }
return Page.WizardPage2;
}
catch(Exception e) { //Handle Exception }
}
}
----------------------------------------------------------------------------------Class Ends
----------------------------------------------------------------------------------WizardPage1 Start
<apex:page Controller="customWizardcontroller" >
page1
<apex:form id="quesAndAns">
<apex:pageBlock title="Bid Pricing" id="pbBidPricing">
<apex:pageblockbuttons >
<apex:commandButton action="{!goNextStep}" value="Next" />
</apex:pageblockbuttons>
</apex:pageBlock>
</apex:form>
</apex:page>
----------------------------------------------------------------------------------WizardPage1 Ends
----------------------------------------------------------------------------------WizardPage2 Start
</apex:page>
----------------------------------------------------------------------------------WizardPage2 Ends
If anyone already faced such issue or can figure out odd in my code please suggest.
Thanks in advance.
Nikhil
Each VF page gets associated with it's own instance of the controller.
You need to pass the Id of the Account obj from the controller instance for WizardPage1 to controller instance for WizardPage2. You can use code like this:
this.acctId = ApexPages.currentPage().getParameters().get('id');
Then you can query for the Account using the acctId, prior to instantiating a new Account in your controller's constructor.
if (acctId != null) {
this.objAccount = [SELECT Id FROM Account where Id = :acctId];
}