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
Venkat Reddy 45Venkat Reddy 45 

paginate saving data to database

Dear Experts,

          I have 3 pages, page 1 has field 1 input and click next. Page 2 has field 2 input and click next, page 3 has field 3 input and click save. Now a record should be inserted with field1,field2 and field 3 values.

Regards,
Venkat.
Best Answer chosen by James Loghry
pconpcon
You can do this with a wizard [1], a flow [2], mutliple visualforce pages* or a single Visualforce page like below:

MultipageController.js
public class MultipageController {
    public String step1 {
        get;
        set;
    }
    
    public String step2 {
        get;
        set;
    }
    
    public String step3 {
        get;
        set;
    }
    
    public String currentStep {
        get;
        private set;
    }
    
    public MultipageController() {
        this.currentStep = 'step1';
    }
    
    public PageReference didStep1() {
        this.currentStep = 'step2';
        return null;
    }
    
    public PageReference didStep2() {
        this.currentStep = 'step3';
        return null;
    }
    
    public PageReference didStep3() {
        this.currentStep = 'step4';
        return null;
    }
    
    public PageReference saveSteps() {
        // Do stuff to create object
        return new PageReference('/');
    }
}

Multipage.vfp
<apex:page controller="MultipageController">
    <apex:form id="page">
        <apex:outputPanel rendered="{!currentStep = 'step1'}">
            <apex:outputLabel value="Step 1" for="step1" />
            <apex:inputText value="{!step1}" id="step1" />
            <apex:commandButton action="{!didStep1}" value="Next" rerender="page" />
        </apex:outputPanel>
        <apex:outputPanel rendered="{!currentStep = 'step2'}">
            <apex:outputLabel value="Step 2" for="step2" />
            <apex:inputText value="{!step2}" id="step2" />
            <apex:commandButton action="{!didStep2}" value="Next" rerender="page" />
        </apex:outputPanel>
        <apex:outputPanel rendered="{!currentStep = 'step3'}">
            <apex:outputLabel value="Step 3" for="step3" />
            <apex:inputText value="{!step3}" id="step3" />
            <apex:commandButton action="{!didStep3}" value="Next" rerender="page" />
        </apex:outputPanel>
        <apex:outputPanel rendered="{!currentStep = 'step4'}">
            <apex:outputLabel value="Step 1" for="step4_1" />
            <apex:outputText value="{!step1}" id="step4_1" />
            <apex:outputLabel value="Step 2" for="step4_2" />
            <apex:outputText value="{!step2}" id="step4_2" />
            <apex:outputLabel value="Step 3" for="step4_3" />
            <apex:outputText value="{!step3}" id="step4_3" />
            <apex:commandButton action="{!saveSteps}" value="Save" />
        </apex:outputPanel>
    </apex:form>
</apex:page>

You could also do the same thing with remote actions [3] and do it all in Javascript and Ajax (take a look at ng-force [4] if you are familiar with Angular).  Past this, you'll have to do it on your own and then if you have any specific issues feel free to post specific questions.

* You can pass data via the URL with url parameters

[1] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_wizard.htm
[2] https://developer.salesforce.com/trailhead/business_process_automation/flow
[3] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting.htm
[4] https://github.com/noeticpenguin/ngForce

All Answers

pconpcon
How are these pages being stored and passed to the next page?  Do you have any code that you are currently using that you could share?
Venkat Reddy 45Venkat Reddy 45
I dont have any code and I am looking for code to acheive this functionality.
Venkat Reddy 45Venkat Reddy 45
Please send me code..I guess pages are passed to the next page by clicking next button on page.
pconpcon
You can do this with a wizard [1], a flow [2], mutliple visualforce pages* or a single Visualforce page like below:

MultipageController.js
public class MultipageController {
    public String step1 {
        get;
        set;
    }
    
    public String step2 {
        get;
        set;
    }
    
    public String step3 {
        get;
        set;
    }
    
    public String currentStep {
        get;
        private set;
    }
    
    public MultipageController() {
        this.currentStep = 'step1';
    }
    
    public PageReference didStep1() {
        this.currentStep = 'step2';
        return null;
    }
    
    public PageReference didStep2() {
        this.currentStep = 'step3';
        return null;
    }
    
    public PageReference didStep3() {
        this.currentStep = 'step4';
        return null;
    }
    
    public PageReference saveSteps() {
        // Do stuff to create object
        return new PageReference('/');
    }
}

Multipage.vfp
<apex:page controller="MultipageController">
    <apex:form id="page">
        <apex:outputPanel rendered="{!currentStep = 'step1'}">
            <apex:outputLabel value="Step 1" for="step1" />
            <apex:inputText value="{!step1}" id="step1" />
            <apex:commandButton action="{!didStep1}" value="Next" rerender="page" />
        </apex:outputPanel>
        <apex:outputPanel rendered="{!currentStep = 'step2'}">
            <apex:outputLabel value="Step 2" for="step2" />
            <apex:inputText value="{!step2}" id="step2" />
            <apex:commandButton action="{!didStep2}" value="Next" rerender="page" />
        </apex:outputPanel>
        <apex:outputPanel rendered="{!currentStep = 'step3'}">
            <apex:outputLabel value="Step 3" for="step3" />
            <apex:inputText value="{!step3}" id="step3" />
            <apex:commandButton action="{!didStep3}" value="Next" rerender="page" />
        </apex:outputPanel>
        <apex:outputPanel rendered="{!currentStep = 'step4'}">
            <apex:outputLabel value="Step 1" for="step4_1" />
            <apex:outputText value="{!step1}" id="step4_1" />
            <apex:outputLabel value="Step 2" for="step4_2" />
            <apex:outputText value="{!step2}" id="step4_2" />
            <apex:outputLabel value="Step 3" for="step4_3" />
            <apex:outputText value="{!step3}" id="step4_3" />
            <apex:commandButton action="{!saveSteps}" value="Save" />
        </apex:outputPanel>
    </apex:form>
</apex:page>

You could also do the same thing with remote actions [3] and do it all in Javascript and Ajax (take a look at ng-force [4] if you are familiar with Angular).  Past this, you'll have to do it on your own and then if you have any specific issues feel free to post specific questions.

* You can pass data via the URL with url parameters

[1] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_wizard.htm
[2] https://developer.salesforce.com/trailhead/business_process_automation/flow
[3] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting.htm
[4] https://github.com/noeticpenguin/ngForce
This was selected as the best answer
Venkat Reddy 45Venkat Reddy 45
Excellent Solutions..Thanks
pconpcon
If you could please choose a "best answer" so that this question can be removed from the unresolved queue.