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
Uves RavatUves Ravat 

Open a page on Visualforce by a button



I want to know how i can open another visualforce page from a visualforce page by the use of button.

The first visualforce page i am using i am adding a contact to database which will have a unique id. when i add the user to the database it should open another visualforce to show the details i have added to the database.


Thank You


use the onclick property of the apex:commandbutton to call a javascript function upon click.   In this funciton, put the needed code to open a new window to your URL.

Eugene PozniakEugene Pozniak

Why, Why JS? :))


If you need pop-up window, I think, you have no choice but to use JS. But you also can return PageReference from the Button Action.

VF page:

<apex:page controller="yourController"> 
    . . . 
    <apex:commandButton value="yourName" action="{!yourActionFromController}">
    . . .

 Apex controller:

public class yourController {
    . . .
    public PageReference yourActionFromController() {
        . . .
        // implement your logic
        . . . 
        PageReference yourPage = new PageReference('/apex/yourPage');
        return yourPage ;
    . . .


Uves RavatUves Ravat

Am not fussed of poping up a window as long the data appears on the a new page. i am adding data to an object through visualforce page (creating a new contact). after i have input the data and when i click save contact i want all the data i added appear on a visualforce page.