calling one visualforce page from another

This is regarding calling a visualforce page from another visualforce page.You may need to call a particular visualforce page after pressing a button or when certain criteria is met. We can call a visualforce page using pagereference object as done in the example below.

Here is a visualforce page that has a button "Call visualforce page". Upon pressing this button "Call a visualforce page", a different visualforce page is called.

  Visualforce page having button "Call visualforce Page"

Controller for above visaulforce page

Visualforce page that is called from above visualforce page
Page Name: DemovfPage

Here, in the method "Call_VF_Page" a instance of pagereference object is created wherein the name of the visualforce is passed.
PageReference openvfpage = New Pagereference('/apex'+'/DemovfPage');
Make sure that your return type is pagerefrence which will make sure new visualforce gets opened.

1 comment: