You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
// 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
// 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');