You need to sign in to do that
Don't have an account?
ZAC BONNER 1
Custom Button to update Lead Status to Unqualified
Hello,
I am trying to create a custom button for the Lead Page Layout to mark a lead as "Unqualified". My code is below; I get no syntax errors but I get the following error message when I click it on a Lead record:
" A problem with the OnClick JavaScript for this button or link was encountered:
Unexpected token catch"
My Code:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
{
var url = parent.location.href;
var updateRecords = [];
var update_Lead = new sforce.SObject("Lead");
update_Lead.Id ="{!Lead.Id}";
update_Lead.Status="Unqualified";
updateRecords.push(update_Lead);
result = sforce.connection.update(updateRecords);
parent.location.href = url;
} catch (e) {
alert (e);
}
I am trying to create a custom button for the Lead Page Layout to mark a lead as "Unqualified". My code is below; I get no syntax errors but I get the following error message when I click it on a Lead record:
" A problem with the OnClick JavaScript for this button or link was encountered:
Unexpected token catch"
My Code:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
{
var url = parent.location.href;
var updateRecords = [];
var update_Lead = new sforce.SObject("Lead");
update_Lead.Id ="{!Lead.Id}";
update_Lead.Status="Unqualified";
updateRecords.push(update_Lead);
result = sforce.connection.update(updateRecords);
parent.location.href = url;
} catch (e) {
alert (e);
}
Please use below code and let me know if you will receuve same error message again, you have missed try in your code :
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
try{
var leadstatusupdate = new sforce.SObject("Lead");
leadstatusupdate .ID = "{!Lead.Id}";
leadstatusupdate.Status = "Unqualified";
result = sforce.connection.update([leadstatusupdate]);
if(result[0].success == "true"){
location.reload();
}
else{
alert(
"An Error has Occurred. Error: \r\n" +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Un-expected Error has Occurred. Error: \r\n" +
e
);
}
Thanks,
BM