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
Girija Joshi 5Girija Joshi 5 

How to pass record ID of a current VF page to another VF page?

Hi all,
In first VF page I am getting basic Lead information and I want to pass that information to another VF page which will have detailed information about the Lead. Now after click on Save button I need to pass that record information and then add more info and save that Lead.

Here is my first VF page:
<apex:page controller="myLeadController">
    <apex:sectionHeader title="New Lead Page" />
    <apex:form >
        <apex:pageBlock title="Create a New Lead">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>        
            <apex:pageBlockSection title="Lead Information">
                <apex:inputField id="firstName" value="{!Lead.FirstName}"/>
                <apex:inputField id="lastName" value="{!Lead.LastName}"/>
                <apex:inputField id="companyName" value="{!Lead.Company}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

public class myLeadController {
    
    Lead lead;

    public Lead getLead() {
        if(lead == null) lead = new Lead();
        return lead;
    }
    
    public PageReference save() {
        // Add the lead to the database. 
        insert lead;
        // Send the user to the detail page for the new lead.
       // need to pass the record id to Thankyou Page
        PageReference leadPage = new ApexPages.Thankyou
        leadPage.setRedirect(true);
        return leadPage;
    }

}
Best Answer chosen by Girija Joshi 5
Roy LuoRoy Luo
 public PageReference save() {
        // Add the lead to the database. 
        insert lead;
        // Send the user to the detail page for the new lead.
       // need to pass the record id to Thankyou Page
        PageReference leadPage = new ApexPages.Thankyou
        leadPage.getParameters().put('leadId', lead.Id);
        leadPage.setRedirect(true);
        return leadPage;
    }
In the leadPage controller, you would need to get the leadId out:

String leadId = ApexPages.currentPage().getParameters().get('leadId');
 

All Answers

Roy LuoRoy Luo
 public PageReference save() {
        // Add the lead to the database. 
        insert lead;
        // Send the user to the detail page for the new lead.
       // need to pass the record id to Thankyou Page
        PageReference leadPage = new ApexPages.Thankyou
        leadPage.getParameters().put('leadId', lead.Id);
        leadPage.setRedirect(true);
        return leadPage;
    }
In the leadPage controller, you would need to get the leadId out:

String leadId = ApexPages.currentPage().getParameters().get('leadId');
 
This was selected as the best answer
Girija Joshi 5Girija Joshi 5
Thanks for the reply it helped me to do what ever i was trying to achive.
Roy LuoRoy Luo
Please flag this post as solved. Thanks.
Girija Joshi 5Girija Joshi 5
that's what i am trying but i am not getting option as solved i am getting spam, inappropriate, hateful