You need to sign in to do that
Don't have an account?
Rajesh SFDC
how to solve thiserror:using javascript in list button, lead is not defined
I have a requirement like, need to select multiple records on the list view. After done with the selection of records. If I click the List view custom button, those selected records must be created into another object. here my code giveb below
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
var selectedLeads = {!GETRECORDIDS($ObjectType.Lead)}, index = 0; leads, newobjs = {}, newrec, saveresults;
if(selectedLeads[0]== NULL)
{
alert("select a record atleast");
return;
}
leads = sforce.connection.retrieve('Id,Name', 'Lead', selectedLeads);
while(index < leads.length)
{
newrec = new sforce.SObject('position__c');
newrec.candidate__c = leads[index].Name;
newrec.job_description__c = leads[index].Name;
newobjs.push(newrec);
index += 1;
}
saveresults = sforce.connection.create(newobjs);
error: lead is not defined
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
var selectedLeads = {!GETRECORDIDS($ObjectType.Lead)}, index = 0; leads, newobjs = {}, newrec, saveresults;
if(selectedLeads[0]== NULL)
{
alert("select a record atleast");
return;
}
leads = sforce.connection.retrieve('Id,Name', 'Lead', selectedLeads);
while(index < leads.length)
{
newrec = new sforce.SObject('position__c');
newrec.candidate__c = leads[index].Name;
newrec.job_description__c = leads[index].Name;
newobjs.push(newrec);
index += 1;
}
saveresults = sforce.connection.create(newobjs);
error: lead is not defined
I tried to rewrite the code, In onclick javascript return do not mean return like a function.
Try this and let me know if there are any issues!
***************************************Code Start***************************************
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
var selectedLeads = {!GETRECORDIDS($ObjectType.Lead)};
if(selectedLeads.length === 0)
{
alert("select a record atleast");
}
else
{
var index = 0, newobjs = {}, saveresults;
var leads = sforce.connection.retrieve('Id,Name', 'Lead', selectedLeads);
while(index < leads.length)
{
var newrec = new sforce.SObject('position__c');
newrec.candidate__c = leads[index].Name;
newrec.job_description__c = leads[index].Name;
newobjs.push(newrec);
index += 1;
}
saveresults = sforce.connection.create(newobjs);
}
***************************************Code End***************************************
***************************************Code Start***************************************
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
var selectedLeads = {!GETRECORDIDS($ObjectType.Lead)};
if(selectedLeads.length === 0)
{
alert("select a record atleast");
}
else
{
var index = 0, newobjs = new Array(), saveresults;
var leads = sforce.connection.retrieve('Id,Name', 'Lead', selectedLeads);
while(index < leads.length)
{
var newrec = new sforce.SObject('position__c');
newrec.candidate__c = leads[index].Name;
newrec.job_description__c = leads[index].Name;
newobjs.push(newrec);
index += 1;
}
saveresults = sforce.connection.create(newobjs);
}
***************************************Code End***************************************