---
title: "Integrate Google Form with Salesforce using Google Apps Script"
description: "Learn how to seamlessly send Google Form submissions directly into Salesforce using Google Apps Script for custom integration."
tags: ["Salesforce", "Google Forms", "Google Apps Script", "Integration", "CRM"]
slug: "google-form-salesforce-integration"
keywords: "Salesforce integration, Google Forms automation, Apps Script Salesforce, CRM automation, Lead capture, salesforce company, salesforce crm, salesforce consulting services, salesforce service, salesforce consulting companies, salesforce crm software, salesforce service cloud, salesforce pricing, salesforce partners"
date: 2023-03-08
author: "Jayesh Jain"
category: "Scripting"
featuredImage: "/blog/google_form_salesforce.png"
cta: "Need Custom Salesforce Integration?"
ctaDescription: "Reach out to Tirnav Solutions for advanced Google Forms → Salesforce integration solutions."
---

# Integrate Google Form with Salesforce using Google Apps Script

Let’s see how we can send Google Form submission data directly into Salesforce using Google Apps Script. Google Forms is a powerful tool for collecting data and surveys, and integrating it with Salesforce allows you to automatically store leads, contacts, and more.

---

## Step 1: Create App in Salesforce

First, create a Salesforce Connected App:

- Navigate: Setup → App → App Manager → New Connected App  
- Fill in required details and enable OAuth settings.

<img src="/blog/create_app_salesforce.png" alt="Create App in Salesforce" />
> This app will provide the client ID and secret needed for authentication in Google Apps Script.

---

## Step 2: Create a new Google Form

1. Create your Google Form and add required fields.  
2. Click the three-dot menu → Script Editor.  
<img src="/blog/google_form.png" alt="Create Google Form" />
3. Paste the following sample Apps Script code:

```javascript
//Authorize & get Token
const auth_url = "https://login.salesforce.com/services/oauth2/authorize";
const token_url = "https://login.salesforce.com/services/oauth2/token";

function onSubmit() {
  try {
    var form = FormApp.getActiveForm();
    var allResponses = form.getResponses();
    var latestResponse = allResponses[allResponses.length - 1];
    var response = latestResponse.getItemResponses();
    var payload = {};
    for (var i = 0; i < response.length; i++) {
      var question = response[i].getItem().getTitle();
      var answer = response[i].getResponse();
      payload[question] = answer;
    }

    const salesforceTokenData = getSalesforceToken();
    const salesforce_payload = Utilities.jsonStringify({
      'FirstName': payload.FirstName,
      'LastName': payload.LastName,
      'Phone': payload.Phone,
      'Email': payload.Email,
      'Description': payload.Description
    });

    var contentType = "application/json; charset=utf-8";
    var feedUrl = salesforceTokenData.instance_url + "/services/data/v48.0/sobjects/Contact" + "?_HttpMethod=POST";
    var response = UrlFetchApp.fetch(feedUrl, {
      method: "POST",
      headers: { "Authorization": "Bearer " + salesforceTokenData.access_token },
      payload: salesforce_payload,
      contentType: contentType
    });

  } catch (err) {
    Logger.log("Error submitting data to Salesforce: " + err);
    throw err;
  }
}

function getSalesforceToken() {
  const grant_type = 'password';
  const client_id = '<client id>';
  const client_secret = '<client secret>';
  const salesforce_username = encodeURI('<salesforce login user>');
  const salesforce_password = encodeURI('<password+security token>');

  var payload = {
    'grant_type': grant_type,
    'client_id': client_id,
    'client_secret': client_secret,
    'username': salesforce_username,
    'password': salesforce_password 
  };

  var options = {
    'method': 'post',
    'payload': payload
  };

  var results = UrlFetchApp.fetch(token_url, options);
  var data = JSON.parse(results.getContentText());
  return { 'access_token': data.access_token, 'instance_url': data.instance_url };
}
```

> **Note:** Always include mandatory fields in your form (First Name, Last Name, Email) for Salesforce Contact object validation.

---

## Step 3: Create Trigger in Google Apps Script

To ensure the *onSubmit()* runs when the form is submitted:

- In Script Editor → Edit → Current Project’s Triggers → Add Trigger  
- Select *onSubmit*, event type: *On form submit*

<img src="/blog/google_app_script_trigger.png" alt="Google App Script Trigger" />
---

## Step 4: Test Integration

- Submit a test form entry.  
- Check Salesforce Contact object to confirm the record is created.  

<img src="/blog/salesforce_gas.png" alt="Salesforce Contact" />
---

## Benefits of Direct Integration

- **Eliminate manual data entry**  
- **Seamless lead capture from Google Forms**  
- **Customizable via Apps Script for complex workflows**  
- **Can extend integration to e-commerce, ERP, or other systems**

---

## Conclusion

Integrating Google Forms with Salesforce via Google Apps Script is simple and powerful. For advanced or custom scenarios, Tirnav Solutions can help with Salesforce Apex, LWC, Aura, VisualForce, Triggers, and Workflow automation.

