Find your content:

Search form

You are here

Strange behavior when passing parameters in retUrl and saveUrl


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: . 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.

Attribution to: George S.

Possible Suggestion/Solution #1

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).

Attribution to: techtrekker

Possible Suggestion/Solution #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.

Attribution to: George S.
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content