You need to sign in to do that
Don't have an account?
Micah Perry 18
Pass values to Lead in a Web-to-Lead Visualforce page
I'm new to developing. I'm creating a public visualforce web-to-lead site. I want to pass values to Company, Lead Source, and probably a few others. I tried following a few examples (the /script portions of my VF page is where I tried to pass a value but it's a complete failure). My guess is that I need to establish components and then assign them somehow to the Lead fields.
Any info on how I can prepopulate those values would be great.
My Extension
My VF page
Any info on how I can prepopulate those values would be great.
My Extension
public class myWeb2LeadExtension { private final Lead weblead; public myWeb2LeadExtension(ApexPages.StandardController stdController) { weblead = (Lead)stdController.getRecord(); } public PageReference saveLead() { try { insert(weblead); } catch(System.DMLException e) { ApexPages.addMessages(e); return null; } PageReference p = Page.ThankYou; p.setRedirect(true); return p; } }
My VF page
<apex:page standardController="Lead" extensions="myWeb2LeadExtension" title="Contact Us" showHeader="false" standardStylesheets="true"> <apex:composition template="{!$Site.Template}"> <apex:define name="body"> <apex:form > <apex:inputtext id="mpCompany"/> <script> var mpCompany = "{!$Component.mpCompany}"; </script> <apex:messages id="error" styleClass="errorMsg" layout="table" style="margin-top:1em;"/> <apex:pageBlock title="" mode="edit"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!saveLead}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Contact Us" collapsible="false" columns="1"> <apex:inputField value="{!Lead.Salutation}"/> <apex:inputField value="{!Lead.FirstName}"/> <apex:inputField value="{!Lead.LastName}"/> <apex:inputField value="{!Lead.Email}"/> <apex:inputField value="{!Lead.Phone}"/> <apex:inputField value="{!Lead.Street}"/> <apex:inputField value="{!Lead.City}"/> <apex:inputField value="{!Lead.State}"/> <apex:inputField value="{!Lead.PostalCode}"/> <apex:inputField value="{!Lead.Country}"/> <apex:inputField value="{!Lead.Company}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <script> window.onload=function() { document.getElementById(mpCompany).self = "{!$CurrentPage.parameters.Company}"; }; </script> </apex:define> </apex:composition> </apex:page>
Thanks,
Kaustav
All Answers
Can you please explain what you are trying to achieve in more details.
BTW - you do not need to declare the Lead variable as private final. Declaring a variable as private will result in the variable not being accessible to the VF page.
Thabnks,
Kaustav
Thanks,
Kaustav
http://micahsb-micahperry.cs10.force.com/recruiting
Thanks,
Kaustav
Thanks,
Kaustav