You need to sign in to do that
Don't have an account?
Custom Button to Create a New Object
Hello All,
I am creating a custom button that will create a lead automatically from my custom object, pass over field values to the new created lead from the custom object, and link the newly created lead to the original custom object. I am having trouble with the third part. Basically. I need to store the ID of the newly created Lead, so it can be connected to my custom object, please see below:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var lead = new sforce.SObject("Lead");
var email = '{!Client_Email__c.From_Email_Address__c}';
var name = '{!Client_Email__c.From__c}';
var emaiIID= '{!Client_Email__c.Id}';
lead.email=email;
lead.company = name;
lead.lastname = name;
var result = sforce.connection.create([lead]);
var leadID = '{!Lead.Id}' ;
var clientemail = new sforce.SObject("Client_Email__c")
clientemail.ID = emaiIID
clientemail.Lead__c = leadID
var result = sforce.connection.update([clientemail]);
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}
The code highlighted in bold is causing issues because it is being passed a null value. The lead ID is assigned after I create the object, but i cannot seem to find a way to reference the newly created lead. Any help or guidance on this would be greatly appreciated.
Many Thanks!