0

I have a requirement where I want to navigate from one VF Page to another VF Page using the same controller class. Can someone help me how to achieve this...

1 Answer 1

4

You use a method that has a PageReference return value. For example:

<apex:commandButton action="{!goToPage2}" value="Next Page" />

public PageReference goToPage2() {
  return Page.VFPage2;
}

Assuming the same controller and extensions are used in the new page, the view state will automatically be transferred to the new page.

3
  • Thanks for your help and it worked...
    – user85512
    Nov 2, 2020 at 2:02
  • Thanks for this. How can I redirect to a page that uses different controllers? And I also want to do the navigation to a different tab. Is that possible? Nov 14, 2022 at 11:43
  • @prateekmathur1991 (a) They have to share the same set of controllers to pass view state automatically. Otherwise, you can add URL parameters to get data between pages. (b) navigation between tabs would require some client-side code, so you wouldn't be able to use, for example, apex:commandButton, directly.
    – sfdcfox
    Nov 14, 2022 at 13:19

You must log in to answer this question.