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 web hook Creator |
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:-
- From Setup, enter Profiles in the Quick Find box, then select Profiles.
- Select a profile, and click its name.
- In the Apex Class Access page or related list, click Edit.
- Select the Apex classes that you want to enable from the Available Apex Classes list and click Add your Apex class.
- Click Save.
Send test data |
The Key for your web hook URL should be the last part of Webhook URL that you created,
Successful Message for web hook and Sample Json. |
Comments
Post a Comment