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
himanshu huske 7himanshu huske 7 

Pass parameter of One Page To Another in Visualforce

Hi All,
Can anybody please tell me how to Pass parameter of One Page To Another in Visualforce, like...
Account object has certain input fields in first Vf page, when we input some data and click on button. List of values of these input field is shown in another Vf page.
help me with simple code.
ASIF ALIASIF ALI
You can use setParam element for passing parameters And for invoking another page from one page Use PageReference element in vf page , study about the working of these two elements.
Deepali KulshresthaDeepali Kulshrestha
Hi himanshu,
Greetings to you!

- Below link has a sample of code that how you can pass the values from one VF page to another VF page.Please use the below link : - 
    https://developer.salesforce.com/forums?id=9062I000000IMuyQAG

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Himanshu,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce Page 1: VfPage1
<apex:page controller="VfPageC">
    <apex:form >
        <apex:actionRegion >
            <apex:pageBlock id="pbAccountDetails">
                <apex:pageBlockSection columns="1" collapsible="false">
                    <apex:inputField value="{!account.Name}" required="true" />   
                    <apex:inputField value="{!account.Phone}" required="true" />
                </apex:pageBlockSection>    
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!page2}" value="Next"/>
                </apex:pageBlockButtons>
            </apex:pageBlock>
        </apex:actionRegion>
    </apex:form>
    
</apex:page>

Visualforce Page 2: VfPage2
<apex:page controller="VfPageC" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!page1}" value="Previous" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:outputField value="{!account.Name}"/>
                <apex:outputField value="{!account.Phone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller: VfPageC
public class VfPageC {
    
    public String accId{get;set;}
    public Account account{get;set;}
    
    public VfPageC(){
        account = new Account();
    }
    
    public PageReference page2(){
        return Page.VfPage2;	
    }
    
    public PageReference page1(){
        return Page.VfPage1;	
    }
}

Please refer to the below link which might help you further with the above requirement.

https://gist.github.com/pchittum/7929944#file-viewstatestudy_page2-L5

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi Himanshu,

You can use the below code:

<<<<----First Visualforce Page --->>>>>
 
<apex:page standardController="Contact"
           extensions="myController"
           title="Contact Us" showHeader="false"
           standardStylesheets="true">
    
    <apex:define name="body">
        <center>
            <apex:form >
                <apex:messages id="error"
                               styleClass="errorMsg"
                               layout="table"
                               style="margin-top:1em;"/>
                <apex:pageBlock title="" mode="edit">
                    <apex:pageBlockButtons >
                        <apex:commandButton value="Submit"
                                            action="{!saveContact}"/>
                    </apex:pageBlockButtons>
                    <apex:pageBlockSection title="Register Page"
                                           collapsible="false"
                                           columns="1">
                        <div style="text-align:center">
                            <apex:inputField value="{!Contact.FirstName}" />
                            <apex:inputField value="{!Contact.LastName}"/>
                            <apex:inputField value="{!Contact.Email}"/>
                        </div>
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:form>
        </center>
    </apex:define> 
    
</apex:page>


<<<<---Controller apex --->>>>
 
public class myController {

     private final Contact webContact;

    public myController(ApexPages.StandardController
                                stdController) {
       webContact = (Contact)stdController.getRecord();
    }

     public PageReference saveContact() {
       try {
       insert(webContact);
       }
       catch(System.DMLException e) {
           ApexPages.addMessages(e);
           return null;
       }
       PageReference p = new pagereference('/apex/rerenderpage?id='+weblead.Id);
       p.setRedirect(true);
       return p;
     }
}


<<<<<<----Another Page--->>>>>
Page name:--rerenderpage

<apex:page standardController="Contact"  title="Job Application" 
           showHeader="false" standardStylesheets="true">
    
        <apex:define name="body">
            <center>
                <apex:form >
                    
                    <apex:messages id="error"
                                   styleClass="errorMsg"
                                   layout="table"
                                   style="margin-top:1em;"/>
                    <apex:pageBlock title="" mode="edit">
                        <apex:pageBlockSection >
                            <apex:outputText value="{!Contact.FirstName}" />
                            <apex:outputText value="{!Contact.LastName}"/>
                            <apex:outputText value="{!Contact.Email}"/>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:form>
            </center>
        </apex:define> 
    
</apex:page>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi