Apex/VisualForce

Salesforce Web-to-Lead with reCAPTCHA (Spam Filtering)

Salesforce has provided an out of box, Web-to-Lead for many years now. It is pretty easy to enable this feature and quickly build the customized web form to capture lead’s for your organization.

But this form had a problem as there was no spam filtering – so one could enter junk data into the form and it would create a lead into your organization with the same info. Due to this, it used to be a concern for the organization’s to keep an eye on the Lead data quality. The enhancements introduced in Spring ’17 release will allow you to enable spam filtering with reCAPTCHA from Google. In this topic I will cover both – creating a Web-to-Lead form and enabling the spam filtering. Before I jump onto creating the Web-to-Lead form, we need to create a reCAPTCHA API Key Pair using our google account.

How to create reCAPTCHA API Key Pair?

  1. Make sure you have Google account. If not, sign-up here.
  2. Navigate to Google reCAPTCHA page, login to Google account, and click ‘Get reCAPTCHA’ button.
  3. Enter label, choose type of reCAPTCHA, domain name/s,  accept the Terms of Service and click Register. Make sure this is the domain/s that you will use to host Web-to-Lead HTML.
  4. On the next page, Copy the Site Key and Secret Key.

Now, we will head back to Salesforce Setup – to configure and generate the Web-to-Lead form. Navigate to Setup | Customize | Leads | Web-to-Lead, edit the ‘Web-to-Lead Settings‘, enable, provide a default Lead Creator using the lookup field and save it.

Next, click the ‘Create Web-to-Lead Form‘, select the fields which you want to put it on your Web to Lead form and provide a return url. Tick option for ‘Enable spam filtering (recommended)‘, then you need to create reCAPTCHA API Key Pair using the field lookup window (use the same SiteKey and Secret generated above). Finally click ‘Generate‘ and it will generate the html code – to be used for submitting the leads from a web page. Copy the code and create a web page – either using VisualForce or any other front-end technology.

I have customized the auto-generated code into a VisualForce page in my org to test it out.

Click here for demo

Few important things to note in the code –

  • Do not change the OrgId as it indicates where (which org) to create the Leads.
  • Do not change the Action url and POST Method.
  • Do not alter the existing hidden variables.

Feel Free to provide your valuable comments or point out any issues or scope of improvement in this post.