Created
July 24, 2025 20:06
-
-
Save zanstaszek9/dec0e3b9ec1ff4a939f3641d01b4733e to your computer and use it in GitHub Desktop.
Goole App Script code that can be put into the Google Forms trigger to send data to Salesforce using Web-To-Lead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const SALESFORCE_ORG_ID = '00DQy00000TqD0T'; // Salesforce Instance Org Id, can be taken from generated Web-To-Lead link. | |
| function onFormSubmit(e) { | |
| const reponseFields = e.response.getItemResponses(); | |
| const payload = { | |
| 'oid': SALESFORCE_ORG_ID, | |
| 'first_name': reponseFields[0].getResponse(), | |
| 'last_name': reponseFields[1].getResponse(), | |
| 'company': reponseFields[2].getResponse(), | |
| 'email': reponseFields[3].getResponse() | |
| }; | |
| const formData = []; | |
| for (const key in payload) { | |
| formData.push(encodeURIComponent(key) + "=" + encodeURIComponent(payload[key])); | |
| } | |
| const options = { | |
| 'method': 'post', | |
| 'headers': { 'Content-Type': 'application/x-www-form-urlencoded' }, | |
| 'payload': formData.join("&") | |
| }; | |
| const response = UrlFetchApp.fetch(`https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8&orgId=${SALESFORCE_ORG_ID}`, options); | |
| Logger.log("Response code: " + response.getResponseCode()); | |
| Logger.log("Response body: " + response.getContentText()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment