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
Tom M422Tom M422 

Passing a variable between VF pages

I need to pass a common variable, let's call it "client name", from a custom object through a number of pages that access different tables. Does anyone know how to code that in either the VF page or the extension?

 

Thanks in advance

 

Tom

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

If pages uses the same controller then IT is common at runtime as long as you switch between the pages with VF actions that return the next page.  If you go directly to the url for another page, or use a page reference with redirect=true, then you will get a new instance of the controller so any variables will be lost.

 

But you can most definitely share data via controller variables if you do it right.

All Answers

dipudipu

You need to look at PageReference. Call a function like the one given bellow from your command button.

 

 

public PageReference goToPage() {
      String myId =  ApexPages.currentPage().getParameters().get('myId');
      PageReference pageRef = new PageReference('/apex/specialpage');
      pageRef.getParameters().put('id', myId);
      pageRef.setRedirect(true);
      return pageRef;
   }

 

 

 

Ritesh AswaneyRitesh Aswaney

Or if you just used a common controller for all of these pages, then you wouldn't have to pass parameters. it could just be an instance variable, which is set on the controller.

dipudipu

Common controller is not common at run time. A new instance is created for each page. If you really wan to use common controller use merge fields to save the data in  an Object (table) and use the value from the object. Then you are not really passing parameters yet achieving the same result. 

aballardaballard

If pages uses the same controller then IT is common at runtime as long as you switch between the pages with VF actions that return the next page.  If you go directly to the url for another page, or use a page reference with redirect=true, then you will get a new instance of the controller so any variables will be lost.

 

But you can most definitely share data via controller variables if you do it right.

This was selected as the best answer
Tom M422Tom M422

Thanks All,