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 from one page to other page

I have customer__c object with FirstName_c, LastName_c, DOB_c fields.
First VF page shows  FirstName_c, LastName_c, DOB_c  in cloumn view.
FirstName_c is in commandLink, if we click on any of  FirstName_c in column, its record should be displayed in 2nd VF page. 
Best Answer chosen by himanshu huske 7
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 1 : Vfp1
<apex:page controller="VfpC">
    <apex:form >
            <apex:pageBlock id="pbAccountDetails">
                <apex:pageBlockSection columns="1" collapsible="false">
                    <apex:pageBlockTable value="{!customer}" var="ac">
                        <apex:column headerValue="First Name" > 
                            <apex:commandLink value="{!ac.FirstName__c}" action="{!page2}">
                                <apex:param value="{!ac.Id}" name="idForCus" assignTo="{!recid}"/>
                            </apex:commandLink>
                        </apex:column> 
                        <apex:column value="{!ac.LastName__c}" />
                        <apex:column value="{!ac.DOB__c}" />
                    </apex:pageBlockTable>
                </apex:pageBlockSection>    
            </apex:pageBlock>
    </apex:form>
</apex:page>

Visualforce 2: Vfp2
<apex:page controller="VfpC" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!page1}" value="Previous" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:outputField value="{!cus.FirstName__c}"/>
                <apex:outputField value="{!cus.LastName__c}"/>
                <apex:outputField value="{!cus.DOB__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller : VfpC
public class VfpC {

    public List<Customer__c> customer{get;set;}
    public Customer__c cus{get;set;}
    public string recid{get;set;}
    
    public VfpC(){
        cus = new Customer__c();
        customer = [SELECT Id, FirstName__c, LastName__c, DOB__c FROM Customer__c LIMIT 10];
    }
    
    public PageReference page2(){
        cus = [SELECT Id, FirstName__c, LastName__c, DOB__c FROM Customer__c WHERE Id=:recid];
        return Page.Vfp2;	
    }
    
    
    public PageReference page1(){
        return Page.Vfp1;	
    }
}

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