0

My scenario is when i filled details on page 1 and will click on next button i will get page 2. On that page i have previous button. When i click previous button, already filled on page 1 details should be display. I am not getting any idea that when i click on previous button how can i get filled details there? Anyone can help me out in this?

first page url: https://c.ap6.visual.force.com/apex/formpage1
second page url: https://c.ap6.visual.force.com/apex/formpage2

How can i pass parameters in url?

page 1:

<apex:page controller="formassignment" >
    <apex:form >
        <apex:pageBlock title="Account details">
            <apex:pageBlockSection >
                <apex:outputLabel value="Name"/>
                <apex:inputtext value="{!acts.Name}"/>
                <apex:outputLabel value="Industry"/>
                <apex:inputtext value="{!acts.industry}"/>

            </apex:pageBlockSection>
            <apex:commandButton value="save" action="{!save}"/>
            <apex:commandButton value="continue" action="{!continoue}"/>     
        </apex:pageBlock> 
    </apex:form>
</apex:page>

Page 1 controller

public class formassignment {

    public Account acts{get;set;}
    public formassignment(){
        acts=new account();
    } 
    public pageReference  save(){
        insert acts;
        return null;
    }
    public  PageReference continoue(){       
        PageReference pageRef = new PageReference('/apex/formpage2');
        pageRef.setRedirect(true);
        return pageRef;
    }
}

==========================================================

Page 2:

<apex:page controller="form2details">
    <apex:form >
        <apex:pageBlock title="Emloyee address information">
            <apex:pageBlock >
                <apex:pageBlockSection >

                    <apex:inputText value="{!dtls.phone}"/>
                    <apex:inputText value="{!dtls.Name}"/>


                    <apex:inputText value="{!dtls.BillingCity}"/>

                </apex:pageBlockSection>
            </apex:pageBlock>
            <apex:pageBlockButtons >
                <apex:commandButton value="Next" action="{!Next}"/>
                <apex:commandButton value="previous" action="{!previous}"/>
            </apex:pageBlockButtons>

        </apex:pageBlock>

    </apex:form>
</apex:page>

Page 2 controller:

public class form2details {

    public PageReference previous() {
        PageReference pageRef = new PageReference('/apex/https://c.ap6.visual.force.com/apex/formpage1');
        pageRef.setRedirect(true);
        return pageRef;
    }

    public account dtls{get;set;}

    public form2details(){
        dtls=new account();
    }

    public pagereference Next(){
        insert dtls;
        return null;
    }
}

I am not able to pass parameter in the url. Please, can anyone guide me? thanks

  • check this link:developer.salesforce.com/forums/?id=906F0000000BBQcIAO – Annappa PH May 7 '18 at 11:53
  • I've fixed your question formatting this time, but after 8 months I expect you to put a bit more effort into formatting your own questions. Especially when dealing with code, using some form of indentation, and being consistent with it, is important because it makes your code easier to read. The fewer barriers that you put up to understanding your code and your question, the more answers you are likely to receive. – Derek F May 7 '18 at 13:05
1

You are using setRedirect(true) in your PageReferences.

According to the documentation

This type of redirect performs an HTTP GET request, and flushes the view state, which uses POST. If set to false, the redirect is a server-side forward that preserves the view state if and only if the target page uses the same controller and contains the proper subset of extensions used by the source page.

Basically, the viewstate of your page (what the user has inputted) is not transferred to the controller. Remove setRedirect(true) from your code.


Also, I would recommend to use rendered attribute, to partly render the page and reRender to reload part of the page and display the second step. The content of each sub-page should go to custom VF components.

E.g. Page:

<apex:page controller="Controller">
<apex:form id="form">

    <apex:pageBlock id="step1" rendered="{!currentStep = 1}">
        <apex:inputText ></apex:inputText>
    </apex:pageBlock>

    <apex:pageBlock id="step2" rendered="{!currentStep = 2}">
        <apex:inputText ></apex:inputText>
    </apex:pageBlock>

    <apex:commandButton action="{!next}" value="Next" reRender="form"/>
    <apex:commandButton action="{!back}" value="Back" reRender="form" rendered="{!currentStep != 1}"/>

</apex:form>

Controller:

public with sharing class Controller {

   private Integer currentStep;

   public Controller() {
        this.currentStep = 1;
   }

    public void next() {
        this.currentStep++;
    }

    public void back() {
        this.currentStep--;
    }
}
| improve this answer | |
  • Thanks for your reply but by using rerender we can partially refresh same page but I need to click on previous and go to back page where I can see autopuplate details. – Akanksha Sharma May 7 '18 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.