+ Start a Discussion
mworldmworld 

Auto Redirect with APEX/VF?

I have a situation where I would like to have the user click a button on a detail page and have them then be re-directed to an external site. There are parameters that would vary according to which page they were on when they clicked this button and those parameters would determine the exact destination. Basically, we're talking about having the user re-directed to an external site that is a document archive, so which directory they end up in depends on what record they were looking at in SF.
 
My initial thought was to have the button bring up an intermediate custom VF page that just says "Redirecting to SharePoint" while the custom page controller evaluates the queryString parameters, determines what the exact final URL will be, and then does the re-direct. The problem comes with the fact that we don't seem to be able to execute that re-direct without further action from the user (such as clicking a button on this intermediate page).
 
Does anyone know whether and how it is possible to execute an automated re-direct such as I describe?
 
Mauricio
Ron HessRon Hess
This is done with javascript on a VF page

say you have a destination, and a destination getter method in your apex code

public string getDest() { return .... logic here ; }


Then in the page, you can simply do this

<script >
window.location.href='{!dest}';
</ script >


the dest will fill in on the server, the browser will jump there as soon as it's loaded.
mworldmworld
Thanks Ron!
ESES
You can also use the "action" attribute on the page tag (<apex : page>) if you want an action to be executed on page load.
Code:
<apex:page action="{!redirectMe}">
..
</apex:page>