function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NikPanterNikPanter 

Issue with error handling on custom button

Afternoon all,

Well, neophyte s-control writer here....attempting to write an s-control that will write to the account page, and start a workflow.  However, some accounts do not meet validation rules, and without error handling, it looks like the s-control goes through and completes but of course the workflow isn't triggered as the criteria is not met (the s-control doesn't update the account).  It is likely something small, but would anyone see the err in my ways???  (I am using a custom button that executes javascript...).

Code:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

{
try {
var account = new sforce.SObject("Account"); 

account.id = '{!Account.Id}'; 
account.Four_Month_Blitz_One__c = 'TRUE';
account.Four_Month_Blitz_Two__c = 'TRUE';
result = sforce.connection.update([account]); 

window.parent.location.href="{!URLFOR($Action.Account.View, Account.Id,null , true )}";
}
{
catch(e)
alert("An error has occurred : " + e);
}
}

 Thanks all,

Nik  :smileytongue:

JNicJNic

I have the same problem. I'm using Try Catch in my JavaScript button, but my catch statement doesn't seem to respect my validation rules.

 

Here is a snippet of my button:

try {

L.id = "{!Lead.Id}";
L.OwnerId = "{!$User.Id}";

newRecords.push(L);

result = sforce.connection.update(newRecords);
}
catch (e) {

alert("An error has occurred: "+e);
}

 

 

Any help would be appreciated.

 

Thanks,