Salesforce | Create leads from google form responses

|
| By Webner

Problem: How to create leads from google form responses?

We have a google form and we want to create leads from google form responses.

Solution: -To create lead from google form, follow these steps:-
1. Open google Sheet which contains the responses of google form.
2. Click on the Tools tab and then click on the script editor.
Salesforce | Create leads from google form responses

3. New Screen opens like this..
Salesforce | Create leads from google form responses

Write a code to insert data in the salesforce.

Here is the sample code that inserts leads from the google sheet. In this code, we are using HTML that is generated from the web to lead functionality.

In this code, we are fetching the data of the last row entered in google responses sheet.

function SendtoSalesforce() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var row = sheet.getLastRow();
  var firstname = sheet.getRange(row,2).getValue();
  var city = sheet.getRange(row,3).getValue();
  var company = sheet.getRange(row,4).getValue();
  var email = sheet.getRange(row,6).getValue();
  var resp = UrlFetchApp
      .fetch(
          'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
          {
            method: 'post',
            payload: {
              'oid' : 'xxxxxxxxxxx ',     //salesforce organization id 
              'first_name' : firstname,            //lead field firstname 
              'last_name' : city,                    //lead field name last name
              'email' : email,                         //lead field name email
              'company' : company,           //lead field name company
              'city' : city,                         //lead field name city
              'state' : 'testcity'               ////lead field name city
                        //we can add number of fields we want and assign value according to requirements
            }
          });

  Logger.log(resp.getContentText());
}

4. Click on save button or Press ctrl+s to save the code.
Salesforce | Create leads from google form responses

5. Click On the Run Button to execute the script. You can execute the script by clicking on the run button or using run tab.
Salesforce | Create leads from google form responses

6. The Leads are created successfully in salesforce.You can test in your salesforce account.

4 comments

  1. Thanks for sharing this code. I could see this could be very useful. One question I have that perhaps you would care to answer. Does this code automatically trigger when a row is added or do you have to run it manually? I have noticed in researching this type of task the previous people who documented their efforts were unable to create a trigger to send the data to Salesforce automatically. So, if this is manual, can the code be altered to trigger upon adding a row or is that not possible? Thanks for the feedback!

  2. Very interesting and useful update. Does this trigger automatically? If not, what would need to be done to trigger the script when a new row is added? Thanks for your feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *