Introduction
Webhooks provide a powerful way to connect Google Forms with Salesforce in real-time. This guide walks through the entire process from setup to implementation, including troubleshooting tips.
Section 1: Prerequisites
Before beginning, ensure you have:
- Google Workspace account (for Google Forms and Apps Script)
- Salesforce account with API access enabled
- Basic understanding of:
- Google Apps Script (JavaScript-based)
- Salesforce REST API
- Webhook concepts
Section 2: Implementation Steps
Step 1: Create Your Salesforce Webhook Endpoint
In Salesforce Setup, navigate to:
Setup → Develop → Apex Classes
Create a new Apex REST class:
@RestResource(urlMapping='/form-submissions/*')
global class GoogleFormWebhook {
@HttpPost
global static void handleFormSubmission() {
RestRequest req = RestContext.request;
Map<String, Object> formData = (Map<String, Object>)JSON.deserializeUntyped(req.requestBody.toString());
// Process data and create Salesforce records
Lead newLead = new Lead(
FirstName = (String)formData.get('firstName'),
LastName = (String)formData.get('lastName'),
Email = (String)formData.get('email'),
Company = (String)formData.get('company')
);
insert newLead;
}
}
Deploy the class and note your endpoint URL:
https://yourdomain.my.salesforce.com/services/apexrest/form-submissions
Step 2: Configure the Google Form Webhook
Open your Google Form → Click "⋮" → Script Editor
Paste this script:
function onFormSubmit(e) {
const webhookUrl = 'YOUR_SALESFORCE_ENDPOINT_URL';
const authToken = 'YOUR_SALESFORCE_SECURITY_TOKEN';
const headers = {
"Authorization": "Bearer " + authToken,
"Content-Type": "application/json"
};
const payload = {
"firstName": e.namedValues['First Name'][0],
"lastName": e.namedValues['Last Name'][0],
"email": e.namedValues['Email'][0],
"company": e.namedValues['Company'][0]
// Add other form fields as needed
};
const options = {
"method": "POST",
"headers": headers,
"payload": JSON.stringify(payload),
"muteHttpExceptions": true
};
try {
const response = UrlFetchApp.fetch(webhookUrl, options);
Logger.log("Submission success: " + response.getContentText());
} catch (error) {
Logger.log("Error: " + error.toString());
}
}
Step 3: Set Up the Trigger
In the Apps Script editor:
Go to Edit → Current project's triggers
Click + Add Trigger
Configure:
Function to run: onFormSubmit
Event: "On form submit"
Failure notifications: Daily
Step 4: Test the Integration
Submit a test form
Check:
Apps Script logs (View → Logs)
Salesforce debug logs (Setup → Debug → Logs)
Verify the new Lead record appears in Salesforce
Top comments (0)