+ Start a Discussion
bathybathy 

Trying to create a lead from a Facebook Conversation

hi Guys,

I am trying to create a new lead from facebook conversation as the standard one doesn't give much flexibility. I am using javascript in a custom button to create new lead record.
  here is my code . This is not creating any lead. can anyone help?

Thanks
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 

var newRecords = []; 

var l = new sforce.SObject("Lead"); 


l.first_name = {!sf4twitter__Twitter_Conversation__c.sf4twitter__Author_Real_Name__c}; 
l.Facebook_conversation__c = {!sf4twitter__Twitter_Conversation__c.Id}; 

l.RecordTypeId = "01290000001An45"; 

l.Database_name__c = "Facebook"; 

l.leadsource = "Facebook"; 

l.Company = "Facebook"; 

l.Assigned_to_caller__c = "Jordan Meates"; 

l.Campaign = "70190000000reFr"; 


var result = sforce.connection.create([newRecords]); 

if(result[0].getBoolean("success")){ 
window.location = “/” + result[0].id + “/e?returl=”+ l.Id; 
}else{ 
alert('Could not create record '+result); 
}

 
Best Answer chosen by bathy
bathybathy
Hi Pankaj,

Thanks for you reply. I was able to figure this out.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 

var crecord = []; 

var l = new sforce.SObject("Lead"); 

var c = new sforce.SObject("sf4twitter__Twitter_Conversation__c"); 

c.id = "{!sf4twitter__Twitter_Conversation__c.Id}"; 

var cm = new sforce.SObject("CampaignMember"); 


l.lastName = "{!sf4twitter__Twitter_Conversation__c.sf4twitter__Author_Real_Name__c}"; 

l.Facebook_Private_Message__c = "{!sf4twitter__Twitter_Conversation__c.sf4twitter__Message__c}"; 



l.RecordTypeId = "01290000001An45"; 

l.Database_name__c = "Facebook"; 

l.leadsource = "Facebook"; 

l.Company = "Facebook"; 

l.Assigned_to_caller__c = "Jordan Meates"; 

l.OwnerId = "00590000001B9wH"; 

var result = sforce.connection.create([l]); 

cm.CampaignId = "70190000000reFr"; 

cm.leadid = result[0].id; 

var result2 = sforce.connection.create([cm]); 

var NewlID = result[0].id; 

c.sf4twitter__Lead__c = NewlID; 

c.RecordTypeId = "01290000000ubYI"; 

crecord.push(c); 

result3 = sforce.connection.update(crecord); 



if(result[0].getBoolean("success")){ 
window.location = "/" + result[0].id ; 
}else{ 
alert('Could not create record '+result); 
}
this worked out for me.


 

All Answers

Pankaj_GanwaniPankaj_Ganwani
Hi,

At line no.8 __c should be suffixed if assigning the value to custom field.
l.first_name__c = {!sf4twitter__Twitter_Conversation__c.sf4twitter__Author_Real_Name__c};
 
bathybathy
Hi Pankaj,

Thanks for you reply. I was able to figure this out.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 

var crecord = []; 

var l = new sforce.SObject("Lead"); 

var c = new sforce.SObject("sf4twitter__Twitter_Conversation__c"); 

c.id = "{!sf4twitter__Twitter_Conversation__c.Id}"; 

var cm = new sforce.SObject("CampaignMember"); 


l.lastName = "{!sf4twitter__Twitter_Conversation__c.sf4twitter__Author_Real_Name__c}"; 

l.Facebook_Private_Message__c = "{!sf4twitter__Twitter_Conversation__c.sf4twitter__Message__c}"; 



l.RecordTypeId = "01290000001An45"; 

l.Database_name__c = "Facebook"; 

l.leadsource = "Facebook"; 

l.Company = "Facebook"; 

l.Assigned_to_caller__c = "Jordan Meates"; 

l.OwnerId = "00590000001B9wH"; 

var result = sforce.connection.create([l]); 

cm.CampaignId = "70190000000reFr"; 

cm.leadid = result[0].id; 

var result2 = sforce.connection.create([cm]); 

var NewlID = result[0].id; 

c.sf4twitter__Lead__c = NewlID; 

c.RecordTypeId = "01290000000ubYI"; 

crecord.push(c); 

result3 = sforce.connection.update(crecord); 



if(result[0].getBoolean("success")){ 
window.location = "/" + result[0].id ; 
}else{ 
alert('Could not create record '+result); 
}
this worked out for me.


 
This was selected as the best answer