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
dai tran 6dai tran 6 

How can store variable of controller when change page?

TopController:
public string type {get;set;}
 public PageReference goPage2()
    {
            
       type='abc';
       PageReference p=new PageReference('/apex/page2');
       return p;
    
    }
public void getbyType()
{
 List<Product2> MyProducts=[Select Id From Product2 where type__c=:type];
}
Page1:
<apex:page controller="TopController" showHeader="false" sidebar="false" >
<apex:commandlink action="{!goPage2}" >

Page2:
<apex:page controller="TopController" showHeader="false" sidebar="false"  action="{!getbyType}">

How can store value of [type] to Page2 can use it?

 
Raj VakatiRaj Vakati
Update your code as below  .. Update the page2param param with the actival Param with you wanted to pass to the page2
 
public string type {get;set;}
 public PageReference goPage2()
    {
            
       type='abc';
       PageReference p=new PageReference('/apex/page2?page2param='+type);
       return p;
    
    }
public void getbyType()
{
 List<Product2> MyProducts=[Select Id From Product2 where type__c=:type];
}

 
dai tran 6dai tran 6
Can create a global variable?
Shubham NandwanaShubham Nandwana
Hi dai tran 6,
You can directly use the variable of page1 on page2 by specifying your TopController on page2 as extensions. Just write {!type} and get the value stored on page 2.
You can declare extensions in apex:page tag like
<apex:page extensions="topController">
Reply if any other doubt.
For extensions you can refer to https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts
dai tran 6dai tran 6
Only StandardController and Apex Code controllers are currently supported