You need to sign in to do that
Don't have an account?
Girija Joshi 5
How to pass current lead ID and some fields from on VF page to another VF page
Hi all,
I have a VF page where I am getting basic information for a lead like, FirstPage (VF page) and I am inserting into the lead object. Now FirstPage is calling SecondPage and which is asking to enter some more info and now I want to informaiton from SecondPage to be insertred in the same lead of the FirstPage (I have leadid).
Could anyone please tell me how to do that? My code is below.
<apex:page controller="FirstController">
<apex:sectionHeader title="signup form" />
<apex:form >
<apex:pageBlock title="Create a New formr">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Volunteer Information" columns="1">
<apex:inputField id="firstName" value="{!Lead.FirstName}" required="true"/>
<apex:inputField id="lastName" value="{!Lead.LastName}"/>
<apex:inputField id="Company" value="{!Lead.Company}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
--------------------------------------------------------------------- SecondPage ----------------
<apex:page controller="FirstController">
<apex:sectionHeader title="signup form details" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!Mysave}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Contact Inforamtion" columns="1">
<apex:inputField id="Street" value="{!Lead.Street}" style="width:200px" required="false"/>
<apex:inputField id="City" value="{!Lead.City}" required="false"/>
<apex:inputField id="State" value="{!Lead.State}" required="false"/>
<apex:inputField id="Country" value="{!Lead.Country}" required="false"/>
<apex:inputField id="PostalCode" value="{!Lead.PostalCode}" required="false"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------------------------------- Controller -------------------------------------------------------------------------------
public class VolunteerInformationController {
Lead lead;
String leadId;
public VolunteerInformationController () {
leadId = ApexPages.currentPage().getParameters().get('leadId');
}
public VolunteerInformationController (ApexPages.StandardController controller) {
leadId = ApexPages.currentPage().getParameters().get('leadId');
}
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.
//PageReference leadPage = new ApexPages.Thankyou
PageReference leadPage = new PageReference('/apex/Volunteer_Initial_Signup2');
leadPage.getParameters().put('leadId', lead.Id);
leadPage.setRedirect(true);
return leadPage;
}
public PageReference Mysave() {
//not able to figureout how to insert rest of the information for that lead id
PageReference pageRef = ApexPages.currentPage();
return pageRef;
}
}
I have a VF page where I am getting basic information for a lead like, FirstPage (VF page) and I am inserting into the lead object. Now FirstPage is calling SecondPage and which is asking to enter some more info and now I want to informaiton from SecondPage to be insertred in the same lead of the FirstPage (I have leadid).
Could anyone please tell me how to do that? My code is below.
<apex:page controller="FirstController">
<apex:sectionHeader title="signup form" />
<apex:form >
<apex:pageBlock title="Create a New formr">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Volunteer Information" columns="1">
<apex:inputField id="firstName" value="{!Lead.FirstName}" required="true"/>
<apex:inputField id="lastName" value="{!Lead.LastName}"/>
<apex:inputField id="Company" value="{!Lead.Company}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
--------------------------------------------------------------------- SecondPage ----------------
<apex:page controller="FirstController">
<apex:sectionHeader title="signup form details" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!Mysave}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Contact Inforamtion" columns="1">
<apex:inputField id="Street" value="{!Lead.Street}" style="width:200px" required="false"/>
<apex:inputField id="City" value="{!Lead.City}" required="false"/>
<apex:inputField id="State" value="{!Lead.State}" required="false"/>
<apex:inputField id="Country" value="{!Lead.Country}" required="false"/>
<apex:inputField id="PostalCode" value="{!Lead.PostalCode}" required="false"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------------------------------- Controller -------------------------------------------------------------------------------
public class VolunteerInformationController {
Lead lead;
String leadId;
public VolunteerInformationController () {
leadId = ApexPages.currentPage().getParameters().get('leadId');
}
public VolunteerInformationController (ApexPages.StandardController controller) {
leadId = ApexPages.currentPage().getParameters().get('leadId');
}
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.
//PageReference leadPage = new ApexPages.Thankyou
PageReference leadPage = new PageReference('/apex/Volunteer_Initial_Signup2');
leadPage.getParameters().put('leadId', lead.Id);
leadPage.setRedirect(true);
return leadPage;
}
public PageReference Mysave() {
//not able to figureout how to insert rest of the information for that lead id
PageReference pageRef = ApexPages.currentPage();
return pageRef;
}
}
Hi Girija Joshi ,
In your Mysave method use following approach :
Mysave()
{
Id LeadId = ApexPages.currentPage().getParameters().get('leadId');
if(LeadId ! =null)
{
Lead objLeadToUpsert = new Lead(Id =LeadId ) ;
// Map your fields as shown
objLeadToUpsert.Street = Lead.Street ;
upsert objLeadToUpsert ;
}
// Write your pagereference code
}
Thanks
Ajay
All Answers
This should have worked I think what you are missing is that your instance lead is not getting populated.
You could do :
1. Make lead public Lead lead {get;set;} and Query the lead Record in contructor when you receive id in query parameter
2. Use lead as Standard controller and use extension
If you are trying to build a wizard then you could see : https://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_wizard.htm
Hi Girija Joshi ,
In your Mysave method use following approach :
Mysave()
{
Id LeadId = ApexPages.currentPage().getParameters().get('leadId');
if(LeadId ! =null)
{
Lead objLeadToUpsert = new Lead(Id =LeadId ) ;
// Map your fields as shown
objLeadToUpsert.Street = Lead.Street ;
upsert objLeadToUpsert ;
}
// Write your pagereference code
}
Thanks
Ajay
Thank you for your help. I was missing upsert operation. now it is workig fine. Thank you very much.