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
hari azmeera 8hari azmeera 8 

pass parameters in url of an apex page and retrieve those values

Best Answer chosen by hari azmeera 8
JyothsnaJyothsna (Salesforce Developers) 
Hi Hari,

Please check the below sample code for how to pass parameters form one vf page to another page.

Page1:
 
<apex:page controller="passparameters1control">
 <apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons location="bottom">
 <apex:commandButton value="NextPage" action="{!nextpage}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockSection >
 <apex:inputField value="{!p.First_name__c}"/><br/>
 <apex:inputField value="{!p.Lastname__c}"/>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>
Controller
public with sharing class passparameters1control {

    public customer__c p { get; set; }
    public passparameters1control (){
    p=new customer__c();
    }

    public PageReference nextpage() {
   
    PageReference pr=new PageReference ('/apex/t42passparametpage2?name='+p.First_name__c+'&lastname='+p.Lastname__c);
        return pr;
    }

}

Page2
<apex:page controller="PassParamametersControl">
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons location="bottom">
 <apex:commandButton value="Save" action="{!save}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockSection rendered="{!input}">
 <apex:inputField value="{!c.Email__c}"/><br/>
 <apex:inputField value="{!c.phone_number__c}"/>
 </apex:pageBlockSection>
 <apex:pageBlockSection rendered="{!output}">
 <apex:outputfield value="{!c.First_name__c}"/>
 <apex:outputfield value="{!c.Lastname__c}"/>
 <apex:outputfield value="{!c.Email__c}"/>
 <apex:outputfield value="{!c.phone_number__c}"/>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>

Controller
 
public with sharing class PassParamametersControl {

    public boolean input { get; set; }

    public boolean output { get; set; }

    public customer__C c { get; set; }
    public PassParamametersControl(){
      c=new customer__c();
      input=true;
      output=false;
    }

    public void save() {
    output=true;
    input=false;
   c.First_name__c= ApexPages.currentPage().getParameters().get('name');
   c.Lastname__c= ApexPages.currentPage().getParameters().get('lastname');
   insert c;
        
    }

}

Hope this helps you!
Best Regards,
Jyothsna

All Answers

sandeep sankhlasandeep sankhla
HI Hari,

You can simply pass the parameters with names and then with same names you can get those in apex classes.

if you want to pass id or status in one page then pass it like below. You need to frame the URL which will consists the label and value.

URL: apex/demopage?Id='12121212'&status='completed'.

in constructor you can use following code to get the values from URL.

public void demopagecontroller()
{
String strStatus = apexpages.currentpage().getparameters().get('status');
String strId = apexpages.currentpage().getparameters().get('id');

}
Let me know if it helps you.
Thanks
JyothsnaJyothsna (Salesforce Developers) 
Hi Hari,

Please check the below sample code for how to pass parameters form one vf page to another page.

Page1:
 
<apex:page controller="passparameters1control">
 <apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons location="bottom">
 <apex:commandButton value="NextPage" action="{!nextpage}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockSection >
 <apex:inputField value="{!p.First_name__c}"/><br/>
 <apex:inputField value="{!p.Lastname__c}"/>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>
Controller
public with sharing class passparameters1control {

    public customer__c p { get; set; }
    public passparameters1control (){
    p=new customer__c();
    }

    public PageReference nextpage() {
   
    PageReference pr=new PageReference ('/apex/t42passparametpage2?name='+p.First_name__c+'&lastname='+p.Lastname__c);
        return pr;
    }

}

Page2
<apex:page controller="PassParamametersControl">
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons location="bottom">
 <apex:commandButton value="Save" action="{!save}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockSection rendered="{!input}">
 <apex:inputField value="{!c.Email__c}"/><br/>
 <apex:inputField value="{!c.phone_number__c}"/>
 </apex:pageBlockSection>
 <apex:pageBlockSection rendered="{!output}">
 <apex:outputfield value="{!c.First_name__c}"/>
 <apex:outputfield value="{!c.Lastname__c}"/>
 <apex:outputfield value="{!c.Email__c}"/>
 <apex:outputfield value="{!c.phone_number__c}"/>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>

Controller
 
public with sharing class PassParamametersControl {

    public boolean input { get; set; }

    public boolean output { get; set; }

    public customer__C c { get; set; }
    public PassParamametersControl(){
      c=new customer__c();
      input=true;
      output=false;
    }

    public void save() {
    output=true;
    input=false;
   c.First_name__c= ApexPages.currentPage().getParameters().get('name');
   c.Lastname__c= ApexPages.currentPage().getParameters().get('lastname');
   insert c;
        
    }

}

Hope this helps you!
Best Regards,
Jyothsna
This was selected as the best answer