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.


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++) {
        } catch(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?



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 as success, id, and errors. It is in the errors 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.

1 Answer 1



If I'm not mistaken, within a for loop console.log(e); will only allow you to capture one error message per loop instead of all of them at once. I know this is often the case with error logging within Apex for loops when iterating through lists, but can't say for certain with respect to Ajax.

Have you looked in the Ajax Toolkit Developer's Guide? You might want to look at this particular page on logging which requires you to also cross reference the Apex Developer's Guide plus links to the SOAP API.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .