Activity › Forums › Salesforce® Discussions › How can we pass Parameter from one Vf page to Another Visualforce page in Salesforce?
-
How can we pass Parameter from one Vf page to Another Visualforce page in Salesforce?
Posted by Suraj on April 13, 2017 at 1:36 PMHow can we pass Parameter from one Vf page to Another Vf page?
Manpreet replied 9 years, 1 month ago 2 Members · 1 Reply -
1 Reply
-
Hi suraj,
Step 1: Create a Visualforce page called SamplePage1….
<apex:page >
<apex:outputlink value=”/apex/SamplePage2″> Click Here <apex:param name=”msg” value=”success”/> </apex:outputlink>
</apex:page>Step2: Create a Visualforce page called SamplePage2
<apex:page controller=”Sampleclass”> </apex:page>
Step 3: On SamplePage1 Click on the ” Click Here” link. You will see that when you click on the link you will navigate to the SamplePage2. Check the URL now..
https://na5.salesforce.com/apex/SamplePage2?msg=successYou can see that the parameter ” msg” with value “success” has been passed to the new page.
Pagereference().getParameters().put()PageReference is a type in Apex. Read the documentation here.
When you click a command button or a command link in a visualforce page, you call a method. The return type
of this method would be a PageReference meaning that, after clicking the button the user will be redirected to a
new Page. Below is a sample code, which shows how to pass parameters from a PageReferencepublic Pagereference gotonewpage()
{
PageReference pageRef = Page.existingPageName;
pageRef.getParameters().put(‘msg’,’success’);
return PageRef
}
existingPageName – actual name of a visualforce page
Retrieve Parameter Values in Apex Class:
The Apex Class code would bepublic class Sampleclass
{
Public String message = System.currentPagereference().getParameters().get(‘msg’);
}So now, the variable “message” would store the value of your parameter “msg”….
Thanks.
Log In to reply.