function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arun BalaArun Bala 

URLFOR & retURL

Hello folks,
Can someone advise me as to how we can get the return URL of a page in a visualforce controller ? My assumption is that it is not possible for VF controller to know from which page it was invoked. So , in order to pass the retURL as a URL parameter(yes, I am calling the visualforce page using a s-control URL), how can I retrieve the same. For e.g.: if I am on a Accounts List page, how do I retrieve its URL ?  [on click of a custom button on the Accounts List page, I invoke the VF page using JS NavigateToURL).

Any help would be greatly appreciated !


Thanks,
A B


Message Edited by Arun Bala on 12-10-2008 01:47 PM

Message Edited by Arun Bala on 12-10-2008 01:48 PM
Ron HessRon Hess
In your controller, you can call PageReference.getUrl()  to learn the URL

so, it would be something like
ApexPages.currentPage().getUrl()
TehNrdTehNrd
If you URL looks like this:

https://cs2.salesforce.com/a0SR0000000WUpL/e?retURL=%2Fa0SR0000000WUpL

String retURL = System.currentPageReference().getParameters().get('retURL');

You may be able to use ApexPages.currentPage().getParameters().get('retURL'); but I'm not sure.



Message Edited by TehNrd on 12-10-2008 02:27 PM
Arun BalaArun Bala
Hi Ron & TechNrd,
Appreciate your quick responses.  But still I would need your help :-)

Looks like my question was not clear. I am rephrasing it as below to clear the ambiguity in my question:

1. I open the accounts tab and view the recently created accounts.

2. Here I also have a custom button called 'X' on the Accounts view page (recently created accounts). On click of the button, I execute a JS to do some validations and then do a NaviagateToURL(Visualforce page URL). The visualforce page URL doesnt have the 'retURL' appeded to it. My question is how can I frame the return URL , that will help me return back to the accounts view page displaying recently created accounts.

3. The visualforce page also opens up . But in the controller, if I do a
System.currentPageReference().getParameters().get('retURL');, nothing will be returned as I am not passing the retURL.

What I noticed is even if I do a URLFOR('/apex/vfpage',null,null), the retURL is not getting appended.

Many a thanks,
Arun B


Message Edited by Arun Bala on 12-10-2008 04:57 PM
TehNrdTehNrd
Are you currently passing any parameters or is this VF page using the standard controller?

If the button is executing an onclick javascript you should easily be able to append the retURL to the url:

I don't think my syntax is correct but you can get the idea.

String url = '/apex/mypage?id={!Opportunity.Id}&retURL={!Opportunity.Id}';
Arun BalaArun Bala
HiTehNrd,
I got your idea. Had it been returning to a particular account page, I would have used that method. But I need to return back to the Account View page (the page that lists my latest filter criteria - Recently view accounts or Recently created accounts.

My URL on the account view page currently looks like : https://na1.salesforce.com/001?fcf=00B300000031lHm. But I am not sure how can I get this id 00B300000031lHm or the inbuilt return URL (retURL=%2F001%3Ffcf%3D00B300000031lH).





Message Edited by Arun Bala on 12-10-2008 05:19 PM

Message Edited by Arun Bala on 12-10-2008 09:08 PM