Salesforce Web to lead and Web to Case using Javascript [CORS Proof !]

This article will not explain what is already available in Salesforce documentation. We will better discover advanced use cases to extend Web2Lead usage. If reCAPTCHA is used in web-to-lead or web-to-case configuration, the transformation to an API as explained below will not work to send Leads or Cases.

Salesforce does not provide any Web2Lead API, we will have to create our own, based on the same formular. We cannot just use Ajax to POST the data to the end point, because Salesforce does not provide the CORS headers (Access-Control-Allow-Origin), and default browser configuration does not permit cross-domain Ajax calls.

We need something dynamic, that will create the field/value pairs and send it to Salesforce. As we cannot use Ajax/XMLHttpRequest, we will have to use javascript to dynamically generate the form and post the form. Below is the generic function and basic call:

Source: https://www.adminbooster.com/blog/hacking_web2lead_web2case

Leave a Comment