Salesforce Integration with Google Lead Ad Form

Authored by: Shivam Gupta 

Hello people of the internet, this is my first blog(Hopefully not the last)!!

Recently I had an interesting client requirement.The client has a paid google campaign running over the internet and has a lot of Google lead AD forms, through which the sales team is creating a pipeline of leads. The leads originally needed to be downloaded  manually each time the form was submitted and hence a Google excel sheet was created for the leads and then imported into salesforce manually. 

Clients request was simple Automate this cumbersome process.

Upon my feasibility check I came across a lot of 3rd party paid applications that did the same eg. Zapier, but in my quest to find a free and a cheap method I stumble upon API integration through web hooks. Well web hooks in a simple language is an automated message sent by an application to another if an event happens.

The difference between web hooks and Rest API, well go on google it😉!

So let's get started, The google lead Ad has an export option at the end of each form and it speciafically asks about the web hook URL and key. But how do we make a web hook this is where our trailblazer community came to my help. I came across this saviour of a person James Ward he shares his personal Heroku website link to create a web hook. Here is the link.

Salesforce Webhook Creator

Salesforce web hook Creator


Moving on Login via Salesforce I am doing this on a sandbox org so choose accordingly, Now for creating a web hook for our salesforce includes making any of our Visual force as page Public site in salesforce and pasting its link as shown in the video by James Ward.

Next create an APEX Class with both Post and Get Method, see my apex class:


@RestResource(urlMapping='/Your unique domain name/*')

global without sharing class Realcode {

    @HttpPost

    global static void doPost() {

        

        Restresponse response = RestContext.response;

        response.addheader('Content-Type', 'application/json');

        string responsestring= restcontext.request.Requestbody.tostring();

        system.debug(system.LoggingLevel.DEBUG,'****\n '+responsestring);

        response.responseBody = blob.valueOf('{success: true,event:"unknown"}');

        response.statusCode = 200;    

       

    }

    @HttpGet

    global static string initPostService() {

        return '{"message":"Connection Successful"}';

    }

    

    

    

}


Now after creating an apex class, add this APEX class to your hosted Public Visual force site created earlier:-

  1. From Setup, enter Profiles in the Quick Find box, then select Profiles.
  2. Select a profile, and click its name.
  3. In the Apex Class Access page or related list, click Edit.
  4. Select the Apex classes that you want to enable from the Available Apex Classes list and click Add your Apex class.
  5. Click Save.


Well now if you have followed my steps till here, then Voila you have made it to the summit, Now we test with our Newly created Web hook on Google Lead Ad form.

Send test data



The Key for your web hook URL should be the last part of Webhook URL that you created,






If the send test data is successful, Then our web hook has captured the response in the Json mentioned below. And the web hook works perfectly!! Well done the integration is complete check your salesforce log to capture the data.

The Response Json should like this

Successful Message for web hook and Sample Json.


Well now we have successfully integrated salesforce with google lead AD's. Now go on and capture your response and extract the fields and let your automation do the work. Good luck Trailblazing.

Any further contributions on the project are welcome! 
For further inquiries please message me on any of the below:
Email: Shivam184@yahoo.in



















Comments