+ Start a Discussion
lilolilo 

navigate between VF pages

Hello

probably very stupid question, but i am newbie

 

I will have a VF page ( called page3 for example) that may be used fm more than one VF page

 

what is the best way to navigate  fm page1 (with command button or outputlink) to page3

so that when i am on page3, page3 "knows" where to return to (via custom Back link)

Best Answer chosen by Admin (Salesforce Developers) 
VisualForceVisualForce

Hi..

 

 When u call page3 from page1 pass page3 id or name along with calling method.

 

In page3 get this id and assign this value to back button..

 

Sample Code:

Page Page1 <apex:commandbutton value="Page3" action="Move_Page3"/> controller Page1 public pagereference Move_Page3() { pagereference page= new PageReference('/apex/<Page3vfname>?Name=Page1'); page.setRedirect(true); return page; } Page Page3 <apex:commandbutton value="Back" action="Back"/> controller Page3 public pagereference Back() { pagereference back_page= new PageReference('/apex/'+ApexPages.currentPage().getParameters().get('Name')); back_page.setRedirect(true); return back_page; }

 

All Answers

aalbertaalbert

I think the "Creating a Wizard" tutorial in the Visualforce Developer's Guide shows most of the key concepts you are referring to. It shows how to navigate across multiple Visualforce pages, but keep the same controller across all the pages. 

 

I hope this helps. 

 

-Andrew

VisualForceVisualForce

Hi..

 

 When u call page3 from page1 pass page3 id or name along with calling method.

 

In page3 get this id and assign this value to back button..

 

Sample Code:

Page Page1 <apex:commandbutton value="Page3" action="Move_Page3"/> controller Page1 public pagereference Move_Page3() { pagereference page= new PageReference('/apex/<Page3vfname>?Name=Page1'); page.setRedirect(true); return page; } Page Page3 <apex:commandbutton value="Back" action="Back"/> controller Page3 public pagereference Back() { pagereference back_page= new PageReference('/apex/'+ApexPages.currentPage().getParameters().get('Name')); back_page.setRedirect(true); return back_page; }

 

This was selected as the best answer
lilolilo

Thnaks a lot

both  answers were very helpful to me