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
Dilyan DimitrovDilyan Dimitrov 

Pass a parameter from one controller to another

Hello,

I would like to know how to pass a parameter from one cotroller to another controller?

For example I am trying to pass the accountId value by using the following code in the first controller
 
public PageReference goToNextPage()
{
PageReference pageRef = Page.MyNextPage;
pageRef.getParameters().put('AccId', accountId);
return pageRef;
}

and according to the log file 

DEBUG|pageRef System.PageReference[/apex/newconvtomerch?AccId=00156000002zGVsAAM

the value I need is added to the AccId.

The problem is that by using the following code

String AccountId = ApexPages.currentPage().getParameters().get('AccId');
 

 I can not get the AccId value in the second controller which actually is the Extension controller

Could you please advise how to fetch the AccId value I need from the first controller?

Regards,

Dilyan



 

Rahul SharmaRahul Sharma
Your steps are right, Can you see the AccId in the URL when page is redirected to Second page?
Arun Deepan LJArun Deepan LJ
Hi, 
Instead, you can use <apex:param> tag to pass values to a controller variable. Use Value attribute to get the value from one controller and use assignto attribute, to assign that value to another controller.

Have a look at the following
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_param.htm
https://developer.salesforce.com/forums/?id=906F0000000968NIAQ