0

this is my page1

<apex:page standardController="Case" extensions="newClass" showHeader="false" >
        <apex:form >
            <apex:pageBlock title="Case Status">
                <apex:pageBlockSection columns="1">
                    <apex:inputField value="{!Case.Status}"/>
                    <apex:inputField value="{!Case.Reason}"/>
                    <apex:inputField value="{!Case.Priority}"/>
                </apex:pageBlockSection>
                <div>
                    <apex:commandButton action="{!redirectToMyVF}" value="CloseCase"/>
                </div>
            </apex:pageBlock>
        </apex:form>
    </apex:page>

this is my page2

<apex:page standardController="Case" extensions="newClass" showHeader="false" >
    <apex:form >
        <apex:pageBlock title="Case Status">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Case.Status}"/>
                <apex:inputField value="{!Case.Reason}"/>
                <apex:inputField value="{!Case.Priority}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
                <apex:commandButton action="{!saveAndRedirect}" value="Save"/> 
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

my apex class

public class newClass {
    public newClass (ApexPages.StandardController controller) {
    }
    public PageReference redirectToMyVF() {
        PageReference pref = new PageReference('/apex/Page');
        pref.setRedirect(true);
        return pref;
    }
    public PageReference saveAndRedirect() {
        if(controller.Save() != null) {
            PageReference redirectPage = Page.mypage2;
            return redirectPage;
        } return null;
    }
}
1
  • 1
    Generally it's easier and more efficient to maintain just one VF page and hide/display outputPanels as needed. Why do you think you need two separate pages? – David Cheng Nov 17 '17 at 6:31
0

From your code, I assume you create the record on Page2 and then redirect the user to Page1 with the details of the case record that you just created.

To do so, you need to pass the record id of the case record in the URL that you just created, so that when the Page1 loads, it retrieves the information about the record created.

Controller:

public class newClass { public Case caseRecord { get; set; } public newClass (ApexPages.StandardController controller) { } public PageReference redirectToMyVF() { PageReference pref = new PageReference('/apex/Page'); pref.setRedirect(true); return pref; } public PageReference saveAndRedirect() { if(controller.Save() != null) { //save your case record controller.Save(); //retrieve the case record caseRecord = ( Case ) controller.getRecord(); System.debug( caseRecord ); //pass the case id as the URL parameter PageReference redirectPage = '/mypage2?id=' + caseRecord.Id; return redirectPage; } return null; } }

Visualforce page:

<!-- this is the page where you want to show the newly created record details --> <apex:page standardController="Case" extensions="newClass" showHeader="false" > <apex:form > <apex:pageBlock title="Case Status"> <apex:pageBlockSection columns="1"> <apex:inputField value="{!caseRecord.Status}"/> <apex:inputField value="{!caseRecord.Reason}"/> <apex:inputField value="{!caseRecord.Priority}"/> </apex:pageBlockSection> <div> <apex:commandButton action="{!redirectToMyVF}" value="CloseCase"/> </div> </apex:pageBlock> </apex:form> </apex:page>

0

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.