I'm trying to create a web-hook listener to create a new Lead when a form is filled out through google ads. Google has an option to use web-hooks to connect to CRM.
https://i.sstatic.net/9nPx9.jpg
I followed this tutorial over here: https://www.greytrix.com/blogs/salesforce/2018/06/04/creating-an-webservice-in-salesforce-and-using-rest-api-to-externally-access-it/
and made a RestResource class
@RestResource(urlMapping='/Lead/*')
global with sharing class MyRestResource {
@HttpPost
global static String doPost(List<Map<String,String>>user_column_data) {
Map<String, String> user_data = new Map<String,String>();
for( Map<String,String> field_data : user_column_data){
user_data.put( field_data.get('column_id'), field_data.get('string_value') );
}
Lead lead = new Lead();
lead.Status = 'New';
lead.Company = user_data.get('COMPANY_NAME');
lead.Phone = user_data.get('PHONE_NUMBER');
lead.Email = user_data.get('EMAIL');
try{
insert lead;
}
catch (exception e){
System.debug('Failure');
}
return lead.Id;
}
}
I made a salesforce site and gave it access to the above class and the lead object.
https://i.sstatic.net/LWnPk.jpg
Google Ad's also lets me send a test record so it sent this data
{
"lead_id": "TeSter-123-ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz-0123456789-AaBbCcDdEeFfGgHhIiJjKkLl",
"user_column_data": [
{
"column_name": "First Name",
"string_value": "FirstName",
"column_id": "FIRST_NAME"
},
{
"column_name": "Last Name",
"string_value": "LastName",
"column_id": "LAST_NAME"
},
{
"column_name": "User Phone",
"string_value": "+16505550123",
"column_id": "PHONE_NUMBER"
},
{
"column_name": "User Email",
"string_value": "test@example.com",
"column_id": "EMAIL"
},
{
"column_name": "City",
"string_value": "Mountain View",
"column_id": "CITY"
},
{
"column_name": "Region",
"string_value": "California",
"column_id": "REGION"
},
{
"column_name": "Company Name",
"string_value": "CompanyName",
"column_id": "COMPANY_NAME"
}
],
"api_version": "1.0",
"form_id": 15016502442,
"campaign_id": 12582701989,
"google_key": "test",
"is_test": true,
"gcl_id": "TeSter-123-ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz-0123456789-AaBbCcDdEeFfGgHhIiJjKkLl",
"adgroup_id": 20000000000,
"creative_id": 30000000000
}
When checking the sandbox environment, this data doesn't exist.
Any help would be appreciated!
Last Name is a required field on Lead and, in your code, I cannot find the line where you're populating the LastName. That could be an issue.
Also, you can setup debug logs for the Guest Site User in Salesforce to see if there is any exception.