Wednesday 24 May 2017

Create Lead using Web-To-Lead In Salesforce

1. From Setup, enter Web-to-Lead in the Quick Find box, then select Web-to-Lead.

2. Click Edit to enable or change Web-to-Lead settings.

3. If you want automate email replies to prospects, select a default response template. If you set up response rules to use different email templates based on the information prospects provide, the default response template is used when no auto-response rules apply. Templates must be marked Available for Use.
Save your changes. You can choose any template for response as a mail after submit the form.

4. To create a form that captures details on your website, click Create Web-to-Lead Form, and then select fields you want to include.

5. Choose fields from the list you waant to include in form.

6. Specify the complete URL to which users should be directed after they submit their information—for example, your company's home page for a thank you page—and click Generate.

Befor I create URL , I create a page 'thankyou' and write text 'Thank you for submit the form' in heading.
As I create site URl here or you can use your internal url also.
Internal Url-- https://ap5.salesforce.com/0667F000001B7jw
Site Url-- https://demobyarun-developer-edition.ap5.force.com/thankyou

7. After click generate, you will get the HTML code. Copy the HTML code and paste code in text editor like notepad and save file as html extension.

8. Open the html file in browser and fill the information's in fields and submit the form it shows Thank you' message and lead created successfully.

9. In 'thankyou' visualforce page, I am displaying today created Leads. And use corresponding controller to show the list of lead.


HTML CODE:

<!--  ----------------------------------------------------------------------  -->
    <!--  NOTE: Please add the following <META> element to your page <HEAD>.      -->
    <!--  If necessary, please modify the charset parameter to specify the        -->
    <!--  character set of your HTML page.                                        -->
    <!--  ----------------------------------------------------------------------  -->
    
    <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/>
    
    <!--  ----------------------------------------------------------------------  -->
    <!--  NOTE: Please add the following <FORM> element to your page.             -->
    <!--  ----------------------------------------------------------------------  -->
    
    <form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
    
        <input type="hidden" name="oid" value="00D7F000000pWBA"/>
        <input type="hidden" name="retURL" value="https://demobyarun-developer-edition.ap5.force.com/thankyou"/>
        
        <!--  ----------------------------------------------------------------------  -->
        <!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
        <!--  these lines if you wish to test in debug mode.                          -->
        <!--  <input type="hidden" name="debug" value=1>                              -->
        <!--  <input type="hidden" name="debugEmail"                                  -->
        
        <label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br/>
        
        <label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br/>
        
        <label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br/>
        
        <label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br/>
        
        <label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br/>
        
        <label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br/>
        
        <label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br/>
        
        <input type="submit" name="submit"/>
    
    </form>

Use this code to create html file to create Lead from outside of salesforce .
And you can use this code in your org also. Then I create visualforce page with this HTML code.

Visualforce Page:

<apex:page showHeader="false" sidebar="false">
    <!--  ----------------------------------------------------------------------  -->
    <!--  NOTE: Please add the following <META> element to your page <HEAD>.      -->
    <!--  If necessary, please modify the charset parameter to specify the        -->
    <!--  character set of your HTML page.                                        -->
    <!--  ----------------------------------------------------------------------  -->
    
    <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/>
    
    <!--  ----------------------------------------------------------------------  -->
    <!--  NOTE: Please add the following <FORM> element to your page.             -->
    <!--  ----------------------------------------------------------------------  -->
    
    <form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
    
        <input type="hidden" name="oid" value="00D7F000000pWBA"/>
        <input type="hidden" name="retURL" value="https://demobyarun-developer-edition.ap5.force.com/thankyou"/>
        
        <!--  ----------------------------------------------------------------------  -->
        <!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
        <!--  these lines if you wish to test in debug mode.                          -->
        <!--  <input type="hidden" name="debug" value=1>                              -->
        <!--  <input type="hidden" name="debugEmail"                                  -->
        
        <label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br/>
        
        <label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br/>
        
        <label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br/>
        
        <label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br/>
        
        <label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br/>
        
        <label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br/>
        
        <label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br/>
        
        <input type="submit" name="submit"/>
    
    </form>
    
</apex:page>

Visualforce Page(thankyou):-

<apex:page showHeader="false" controller="ShowTodayCreatedLeads">
  <!-- Begin Default Content REMOVE THIS -->
  <center><h1>Thank you for submit the form</h1></center>
  <br/>
  <apex:pageBlock>
      <apex:pageblockTable value="{!lstLead}" var="lead">
          <apex:column headervalue="Lead Name">
              <apex:outputtext value="{!lead.Name}"/>
           </apex:column>
      </apex:pageblockTable>
  </apex:pageBlock>
</apex:page>

Apex Class:-

public class ShowTodayCreatedLeads
{
    public List<Lead> lstLead{get;set;}
    public ShowTodayCreatedLeads()
    {
        lstLead=new List<Lead>([select id,name from Lead Where createddate=today]);
        
    }
}

0 comments:

Post a Comment

If you have any doubts, please let me know.