+ Start a Discussion
LAMCORPLAMCORP 

Does anyone know how to simply redirect a page to a specific URL using VF?

Dear all,

 

I have been looking for a way to redirect a user when they click on a VF page button.

I want to redirect the user away from the standard new buttons found when you first click on any object each object.

 

Similarly to html <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">

 

Does anyone have a solution to this?

 


SRKSRK

To redirect a page to a specific URL using only from VF you can use Javascript

Window.location

 

OR Window.location.href

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

---- vf page---------

<apex:page standardController="account" extensions="db_redirect_cls" >

    <apex:form >

        <apex:pageBlock >

        <apex:outputText >Name</apex:outputText> >

              <apex:inputField value="{!acc.name}"/>

              <apex:outputText >City</apex:outputText>

              <apex:inputField value="{!acc.city_cust__c}"/>

        </apex:pageBlock>

        <apex:commandButton value="save" action="{!save1}"/>

    </apex:form>

</apex:page>

--- Apex Controller------------

public with sharing class db_redirect_cls {

    public account acc{get;set;}

    public db_redirect_cls(ApexPages.StandardController controller)

     {

            acc = new account();

     }

    public pagereference save1()

    {

       pagereference p1;

       p1= new pagereference('https://ap1.salesforce.com/001/o');   //for regirect the welcome page

       p1.setRedirect(true);

       return p1;

    }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

SRKSRK

I belive he mention Using VF

& u can only redirect throw Javascript if u want to use only using VF

window.location

 

or window.location.href

LAMCORPLAMCORP

Hi guys thanks for the response. I am looking for the simplist and quickest answer.

I like the sound of both but favour the Javascript alternative as it is just one line. :)

I will try it out and let you know.