You need to sign in to do that
Don't have an account?
Ken_Koellner
How to return to prior page?
If I want a method in Apex controller to return to the prior page, what should I return for the page reference?
I would assume I can return a URL with the id that was passed in but that would open a new instance of a page. I'd rather just go back.
Take a look at this example. It's the controller for an 3-page Opportunity wizard. It includes the methods for page navigation.
Hope that helps,
Sati
But that example doesn't really answer the question. I want to go back to the page I came from and that example goes to the page of the new object created.
This is the code that navigates between pages from the example:
// The next three methods are used to control navigation through // the wizard. Each returns a reference to one of the three pages // in the wizard. public PageReference step1() { return Page.newOpptyStep1; } public PageReference step2() { return Page.newOpptyStep2; } public PageReference step3() { return Page.newOpptyStep3; }
And then if you look at the Visualforce page for the second page of the wizard, you'll notice these the 2 command buttons:
<apex:page controller="newOpportunityController" tabStyle="Opportunity"> <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/> <apex:form> <apex:pageBlock title="Opportunity Information"> <apex:facet name="footer"> <apex:outputPanel> <apex:commandButton action="{!step1}" value="Previous" styleClass="btn"/> <apex:commandButton action="{!step3}" value="Next" styleClass="btn"/> </apex:outputPanel> </apex:facet> <apex:pageBlockSection title="Opportunity Information"> <apex:panelGrid columns="2"> <apex:outputLabel value="Opportunity Name" for="opportunityName"/> <apex:inputField id="opportunityName" value="{!opportunity.name}"/> <apex:outputLabel value="Amount" for="opportunityAmount"/> <apex:inputField id="opportunityAmount" value="{!opportunity.amount}"/> <apex:outputLabel value="Close Date" for="opportunityCloseDate"/> <apex:inputField id="opportunityCloseDate" value="{!opportunity.closeDate}"/> <apex:outputLabel value="Stage" for="opportunityStageName"/> <apex:inputField id="opportunityStageName" value="{!opportunity.stageName}"/> <apex:outputLabel value="Role for Contact: {!contact.firstName} {!contact.lastName}" for="contactRole"/> <apex:inputField id="contactRole" value="{!role.role}"/> </apex:panelGrid> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Hope that helps,
Sati
I get how that works but I want to return to the page prior to when I got in my VF page.
Example:
I put a customer button on an Opportunity page layout that calls a VF page.
The user hits a button on my VF page. The button calls my controller which does some work and then passes the user back to the page they came from (like they hit the back arrow in their browser).
(Assuming I have the opportunity id pass in as a parameter and saved in a variable called oppId)
I know I can do --
Opportunity opp = [select id from Opportunity where id = :oppId];
ApexPages.standardController controller = new ApexPages.standardController(opp);
or
PageReference oppPage = new PageReference('/' + oppId);
oppPage.setRedirect(true);
But that opens a new page for the opportunity. It doesn't go back.
Maybe what I'm asking just can't be done.
Would I be able to return a page reference iwth a javascript in it?
Something like-- 'javascript:history.back()'