Hello friends, In this tutorial, You are going to see How to Pass Parameter from Visualforce Page to another. This is a very common situation for any web application to Pass data from one Page to another Page.

How to Pass Parameter from One Visualforce Page to another

Create a Visualforce Page called FistPage.vfp from where you will pass the value to the second Visualforce Page

FirstPage.vfp

<apex:page controller="FirstPageController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >Enter the text to be passed: <apex:inputText value="{!sValue}"/></apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Go to Next Page" action="{!CallNextPage}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

Create an Apex class called FirstPageController.

FirstPageController

public class FirstPageController {
public String sValue{get;set;} 
public FirstPageController()
{
 
}
public PageReference CallNextPage()
{
PageReference pg=new PageReference('/apex/SecondPage');
pg.getParameters().put('p1',sValue);
pg.setRedirect(false);
return pg;
}
}

Create a second Visualforce Page which will receive the parameter passed from fist Visualforce Page.

SecondPage.vfp:

<apex:page controller="SecondPageController" >
The received value is {!sValue}
</apex:page>

Create an apex class called SecondPageController.

SecondPageController

public class SecondPageController {
public String sValue{get;set;}
public SecondPageController()
{
sValue=ApexPages.currentPage().getParameters().get('p1');
 
}
}

Output:

Pass Parameter

Click on the Go to Next Page.

Pass Parameter

View More:

Conclusion:

I hope this is a useful topic for you. Please comment for any technical help. Your feedback and suggestions would be appreciated.

Thank You.

Leave a Comment