You need to sign in to do that
Don't have an account?
jsacpt24
custom button to pull from Lead to custom object
I am trying to create a custom button that works for multiple different objects to all come back to my Data_Feasibility_Report__c custom object. I was trying to create the button to pull from the Lead standard object but I keep gettting an error that I am not sure how to fix. Any help would be appreciated. Here is the code that I am trying to write. I am trying to pull the Name from the Lead and the record type as well as a couple custom fields. When I go test the button I get "Invalid or unexpected token".
I tried this another way but I am getting an error the second way I tried as well. Any help on either of these would be appreciated.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} var DFR = new sforce.SObject("Data_Feasibility_Request__c"); DFR.Related_To__c = 'Lead'; DFR.Related_Lead__c = '{!Lead.Name}'; DFR.RecordID=0125C00000005jd; var result = sforce.connection.create([DFR]); if(result[0].getBoolean("success")){ alert('New record updated successfully'); } else{ alert('Error : '+result); }
I tried this another way but I am getting an error the second way I tried as well. Any help on either of these would be appreciated.
{!REQUIRESCRIPT('/soap/ajax/37.0/connection.js')} getDate = function(dateObj){ var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay(); var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth(); return dateObj.getFullYear()+'-'+month+'-'+day; } var oppty = new sforce.SObject('Data_Feasibility_Report__c'); oppty.Related_Lead__c = '{!Lead.Name}; oppty.Related_To__c = 'Lead'; RecordType=0125C00000005jd; result = sforce.connection.create([oppty]); if(result[0].success == 'true'){ alert('An New Opportunity with Name - ' + oppty.Name + ' was Created Successfully.'); }
Here is your working code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var DFR = new sforce.SObject("Data_Feasibility_Request__c");
DFR.Related_To__c = 'Lead';
DFR.Related_Lead__c = '{!Lead.Name}';
DFR.RecordID__c='0125C00000005jd';
result = sforce.connection.create([DFR]);
if(result[0].getBoolean("success")){
alert('New record updated successfully');
}
else{
alert('Error : '+result);
}
let me know if your issue is not resolve
Thanks
Put below code and if its woking then mark it as a best answer
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var DFR = new sforce.SObject("Data_Feasibility_Request__c");
DFR.Related_To__c = 'Lead';
DFR.Related_Lead__c = '{!Lead.Name}';
DFR.RecordID ='0125C00000005jd';
result = sforce.connection.create([DFR]);
if(result[0].getBoolean("success")){
alert('New record updated successfully');
}
else{
alert('Error : '+result);
}
Thanks
I have created same scenario in my dev org and its working fine for me, below is source code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var DFR = new sforce.SObject("Data_Feasibility_Request__c");
DFR.Related_To__c = 'Lead';
DFR.Related_Lead__c = '{!Lead.Name}';
DFR.RecordTypeID='012900000016O3hAAE'; //Please make this record type ID should be present in Data_Feasibility_Request__c object
result = sforce.connection.create([DFR]);
if(result[0].getBoolean("success")){
alert('New record updated successfully');
}
else{
alert('Error : '+result);
}
If its work for you then mark it best solution.
Thanks,
Tejas
**Please make sure this record type ID should be present in Data_Feasibility_Request__c object
Just wanted to check, is your issue resolved?
Thanks,