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
natemanleynatemanley 

Capturing Validation Rule errors with API in an S-Control

I have created a very simple S-Control that is triggered as a pop-up from a button on the Lead Detail page.

The control is designed to make a small edit to the record then refresh the parent window and then close itself.

When a Validation Rule does not allow the Lead record to be updated I can not get the SaveResult object to return any errors.  After looking at the success property I would assume the record had been updated however, no update occurrs.

How do I handle Validation Rule errors using the API in an S-Control???

The SaveResult.success property is true - which I would expect would be false.
The SaveResult.id field is blank - which is expected because no records were updated
The SaveResult.errors object is undefined - which I would expect would have the error message from the Validation Rule.

Here is my code...very simple:
    var soql = "select Id, Status from Lead where id = '" + leadId + "' ";

    var qryResult = sforce.connection.query(soql);

    var leadQry = qryResult.getArray("records");

    if (leadQry.length == 1)
    {
        leadQry[0]["Status"] = status;

        var saveResult = sforce.connection.update(leadQry);

        if (saveResult[0].success)
        {
                alert("Successfully submitted for approval.");
                CloseWindow();
        }
        else
        {
            alert("Submit for Approval failed.\n\nError:\n" + saveResult[0].errors[0].message);
        }
    }
werewolfwerewolf
Are you sure the validation rule is really firing then?  Is the validation rule active?
natemanleynatemanley
Yes.  Absolutely positive.  I have testing the rule many times using the standard interface and it works just fine.