How to pass parameters using PageReference in Salesforce?

First VF Page:

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

public class Sample {
    public String strText {get;set;}
    public Sample() {
    public PageReference nextPage() {
        PageReference pg = new PageReference('/apex/NextPage');
        pg.getParameters().put('str', strText);
        return pg;

Second VF Page:

<apex:page controller="NextPageController">
Value passed in previous page is {!strText}

public class NextPageController {
    public String strText {get;set;}
    public NextPageController() {
        strText = ApexPages.currentPage().getParameters().get('str');



No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit