• Micah Perry 18
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
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
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>

 
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
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>