I'm using a VF page to show Contacts. I have a group of categories (related lists) which are checked or unchecked. When I perform an action on the page, e.g. View, Edit, New, I want SF to remember which categories are checked, and check them again when the user clicks the back button or saves the record.

To do this, I'm setting retUrl and saveUrl where necessary, adding a parameter "rels" onto both which holds the keyPrefixes of the checked related lists. E.g. /apex/MyApexPage?id=003xxxxxxxxxx&rels=a09,a0B,a0K

Here is the code I'm using for this:

<apex:outputLink value="/{!fvv.recordId}/e?retURL={!URLENCODE('/apex/Codi?id='& contact.Id & '&rels='& preSelectedRelListsKeyPrefix &'')}&saveURL={!URLENCODE('/apex/Codi?id='& contact.Id & '&rels='& preSelectedRelListsKeyPrefix &'')}">Edit</apex:outputLink>

When I hover over the links I see the correct retURL and saveURL. This means that preSelectedRelListsKeyPrefix is populating correctly.

In the next page I see the Encoded URLs, i.e.


When I click the back button, I look for the rels parameter in my controller. However, this is null. In the URL rels is missing as well.

However, the weird thing is that it works if I perform an action in the page. Let's say I edit an object in the a0G related List. So the URL I generate would be the same as above.

. Now, if I edit the record, the rels parameter is correctly set, and the salesforce 'newid' parameter is attached, like so: https://na1.visual.force.com/apex/Codi?id=003U000000PL9LNIA1&rels=a0G&newid=a0GU0000005nFJR . But if I click the back button without editing, it doesn't work. And yet I checked for differences between my saveUrl code and my retUrl code and they are identical.

Likewise, the "New" and "View" buttons are not passing the parameter properly. I'm kind of stuck what to do here, since I'm passing everything correctly from my side and it seems to be salesforce that doesn't attach the parameter on the way back.

2 Answers 2


I managed to make this work by using the Cookie class. Instead of outputLinks, I used a commandLink and constructed a Page Reference in the controller like so.

PageReference pr = new PageReference('/'+recordToView+'/e?retURL=/apex/Codi?id='+contact.Id+'&rels='+preSelectedRelListsKeyPrefix);

Cookie relCookie = new Cookie('Checked Related Lists', preSelectedRelListsKeyPrefix, null, 1440, false);

pr.setCookies(new List<System.Cookie>{relCookie});
return pr;

Then in my constructor if the url parameter is empty I check for the Cookie

        Cookie rels = ApexPages.currentPage().getCookies().get('Checked Related Lists');

The result - the checkbox state is maintained even if the user clicks the Browser back button.


retURL is the URL Salesforce redirects to when you click the Cancel Button

saveURL is the URL Salesforce redirects to when Save is clicked.

I cannot think of a supported way to make sure URL Query Parameters are passed when the Browser Back Button is pressed (I'm assuming here by the Back Button, you mean the Back button on the Browser).

  • 1
    You're right. Both the Cancel button and Save button work as expected, it's just the browser back button which takes the last URL of previous page. As the rels parameter is not present (when a checkbox is selected I'm doing a partial page refresh, otherwise I could add the parameter) the checkboxes are not respected. Looks like it's back to the drawing board...
    – George S.
    Nov 30, 2012 at 13:58
  • 1
    Unfortunately so, the Back button is pure evil. Nov 30, 2012 at 17:14

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.