I am writing some javascript to be executed by a custom button on a Lead page. I would like to capture all of the validation errors that may be thrown when I update the page.
It seems that if I save an incomplete record manually, then all of the errors that I've missed are displayed, but when I update the record via javascript, the array of errors only ever has one element in it.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var status = '{!Lead.Status}';
if( status != "Submitted for Validation") {
var leadUpdate = new sforce.SObject("Lead");
leadUpdate.Id='{!Lead.Id }';
leadUpdate.Status="Submit for Validation";
if(leadUpdate!=null) {
try {
var updateLeadResult = sforce.connection.update([leadUpdate]);
for(var i = 0; i < updateLeadResult.length; i++) {
console.log(updateLeadResult[i]);
}
console.log(updateLeadResult);
//location.reload(true);
} catch(e) {
console.log(e);
}
}
}
In the code above, I'm just hoping to log all the errors. I only ever get one returned.
Is this normal behaviour, or is there a way to get errors for multiple fields returned?
Thanks
Edit
I didn't make a couple of things clear in my original post.
- Firstly, This is not for a Visualforce page, this is for a custom button added to a standard lead page.
- Secondly, I'm not expecting errors to be thrown and then caught by the catch of the try/catch block. The errors are in the JSON object returned by the update method, which in my code is the
updateLeadResult
variable. Within that JSON is an array of objects, which contains properties such assuccess
,id
, anderrors
. It is in theerrors
property that I was hoping to see more than one error returned. - I am merely looking to read those errors and use javascript to append them to the div with class
pbError
, which is in the standard page.