Activity Forums Salesforce® Discussions How can we pass Parameter from one Vf page to Another Visualforce page in Salesforce?

  • Manpreet

    Member
    April 13, 2017 at 4:13 pm

    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=success

    You 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 PageReference

    public 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 be

    public 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.

Popular Salesforce Blogs

Popular Salesforce Videos