+ Start a Discussion

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...).


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 )}";
alert("An error has occurred : " + e);

 Thanks all,

Nik  :smileytongue:


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}";


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

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



Any help would be appreciated.