I have a page that shows records for an object and I need to be able to select some, and then once the "Add Packages" button is clicked I need the page to return to the previous page after completing it's function in Apex.

I attempted to try getting the retURL but getting that doesn't seem to be working.

I also tried to use the standardController.cancel(); page reference but that doesn't seem to work due to the rerender on the button, which needs to be there to pass the variable.

Does anyone have any suggestions on this?


<apex:page standardController="Opportunity_Package__c" extensions="MetadataPackageEditor" sidebar="false" showHeader="false">
  <apex:outputPanel id="all">
  <apex:form >

      <apex:outputField value="{!Opportunity_Package__c.Opp_Package_Rel__c}"/>

      <apex:pageBlock title="Select Package(s)">
      <apex:pageMessages />

          <apex:pageBlockTable value="{!packages}" var="o" id="table">
              <apex:column title="Select" headerValue="Select">
                  <apex:inputCheckbox value="{!o.selected}"/>
              <apex:column value="{!o.pack.Name}"/>
              <apex:column value="{!o.pack.Products__c}"/>
              <apex:column value="{!o.pack.PPU_Discount__c}" headerValue="Price per Unit Discount"/>
      <apex:commandButton value="Add Packages" action="{!processAndAddSelected}" rerender="all">
          <apex:param name="oppIdParam" value="{!Opportunity_Package__c.Opp_Package_Rel__c}" assignTo="{!oppId}"/>
      <apex:commandButton action="{!cancel}" value="Cancel"/>

  • did you decode the retUrl? Commented Mar 4, 2015 at 20:02
  • How would I go about doing that? Commented Mar 4, 2015 at 20:51
  • <apex:page controller="MyController123"> <apex:form id="all"> <apex:commandButton action="{!callme}" value="callme" oncomplete="myActionMethod();return false;" rerender="all"> <apex:actionFunction name="myActionMethod" action="{!submitEmp}" /> </apex:commandButton> <apex:outputLabel Value="Value"></apex:outputLabel> <apex:outputText value="{!textValue}" ></apex:outputText> </apex:form> </apex:page>
    – Suresh
    Commented Mar 4, 2015 at 20:55
  • public class MyController123 { public String textValue { get; set; } public PageReference callme() { textValue = 'Hi Friend'; return null; } public PageReference submitEmp() { textValue = textValue + ' How are you'; PageReference pgref=new PageReference ('/'); //frame you url where the page should land return pgref; // return null; } }
    – Suresh
    Commented Mar 4, 2015 at 21:01
  • So I see you put in how to call an actionFunction, but this doesn't particularly help. I have absolutely no idea what needs to be done to get the proper url from retURL and the resources for it are just shoddy. Commented Mar 4, 2015 at 21:58

2 Answers 2


Why not using JavaScript? Either you can store the previous URL in localStorage and go back there later with document.location or try simply to use



  • Thank you for the suggestion, but it only returns a blank white page now Commented Mar 5, 2015 at 16:42
  • the above will not work if you have any action on the page and then click the back button
    – Nick
    Commented Jan 24, 2017 at 17:22

try this,

PageReference returnPage = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));  

You must log in to answer this question.

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