+ Start a Discussion
gs0551gs0551 

Unable to Save the field values in VF

I create two vf pages(2 step wizard). the page 1 have next and cancel button and page 2 have previous, save and cancel button.

Requirement: allow users to enter the values in the fields and save it. User should also be able to view the values of the field entered in page1 and page2

 

Problem: The users can enter the data in both the pages but after saving the record and when the user view them. only the field values from page1 is visible and all the field values form page2 is empty. My controller code only inclues navigation from one page to another. Save, previous, next and cancel are the standard button (code in the VF page)

 

Need help is knowing why field values from page1 is saved and page2 is empty.

 

public class qualityCheckController {

    public qualityCheckController(ApexPages.StandardController controller) {

    }
    public PageReference step1() {
      return Page.QualityCount1;
   }

   public PageReference step2() {
      return Page.QualityCount2;
   }

}

 

 

JitendraJitendra

As per your code, i can conclude that in step1 you are returning different page than step2 and this is the problem. The variable value is not persisted. If you want to create the Wizard like behavior then same controller should be used for same page otherwise the value will not be persisited.

 

Let me know in case you need more clarification.

gs0551gs0551

Can you plese tell me how my controller code should look like ?

JitendraJitendra

Hi,

 

Please have a look at below code. This is not working code but the example that hoe to create a wizard:

Apex Page

<apex:page standardController="YourStandardController" extensions="YOUR_EXTENSION_NAME" >

<!-- This is Page 1 -->
<apex:pageBlock title="This is Page 1" mode="edit" rendered="isPage1">
<!--
Your code for page 1
....
on Next button call method
-->
<apex:pageBlockButtons >
  <apex:commandButton value="Next" action="{!goToPage2}" />
</apex:pageBlockButtons >
</apex:pageBlock>



<!-- This is Page 2 -->
<apex:pageBlock title="This is Page 2" mode="edit" rendered="isPage2">
<!--
Your code for page 2
-->
<apex:pageBlockButtons >
  <apex:commandButton value="Save" action="{!Save}" />
</apex:pageBlockButtons >
</apex:pageBlock>


</apex:page>

Extension OR controller code

class YOUR_EXTENSION_NAME
{
    //Declare a sObject variable which is going to be saved
	<Object_TYPE> objToSave;
	
	//If it is the extension then create a constructor with Controller as Argument
	
	
	//Decalre two boolean variable to decide that which page should be visible?
	Boolean isPage1;
	Boolean isPage2;
	
	public PageReference goToPage2()
	{
		//Any validation or something if you want
		isPage1 = false;
		isPage2 = true;
		
		return null;
		
	}
	
	public Pagereference Save()
	{
		insert objToSave;
		return <PAGE WHERE YOU WANT TO RETURN AFTER SAVE>
	}
}