0

I have a VF page where Account data is entered, before saving the record I am redirecting to a different page here I don't want to pass already entered values as parameters but I want to maintain view state (I shouldn't loose already entered data on Vf page).

Is it possible to do that ?

Here is my code :

AccountPage :

<apex:page standardController="Account" extensions="selectPrice">
       <apex:form>
        <apex:pageMessages ></apex:pageMessages>

        <apex:pageBlock
            <apex:pageBlockButtons >
                <apex:commandButton action="{!saveaccs}"
                    value="Save " />
                <apex:commandButton action="{!cancel}" value="Cancel" />
            </apex:pageBlockButtons>

            <apex:pageBlockSection >
                   <apex:inputField value="{!Account.Name }" id="RID" required="true" />

                    <apex:inputField value="{!Account.Region__c}" />

                     <apex:inputField value="{!Account.State__c }" required="true" />

                    <apex:inputField value="{!Account.Price__c}" />

             </apex:pageBlockSection>
            <apex:commandButton action="{!selectPrice}"  value="Select Price"> </apex:commandButton>

        </apex:pageBlock>

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

Controller :

public class selectPrice {

    public controllercls(ApexPages.StandardController controller) {
        // code
        accountRec = (Acount)controller.getRecord();

        //end

    }
    public PageReference selectPrice() {
        PageReference pr = new PageReference('/apex/otherpage?Name='+accountRec.Name);
            return pr;

    }
}

Otherpage:

<apex:commandButton action="{!gobacktoAccPage}"  value="Go Back"> </apex:commandButton>

Controller for Otherpage:

public PageReference gobacktoAccPage() {
        PageReference pr = new PageReference('/apex/AccountPage');// when I go to this page already entered values are showing as null
            return pr;

    }

1 Answer 1

0

I think it should be possible in general and there are two crucial aspects in particular to achie the desired behaviour:

  • the controller must be shared between the pages
  • the page reference needs to be setRedirect(false)

See this example for more details

How do I persistent data between VF pages (that change the view state) that share one controller?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .