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

Help Extract error from update result



I would like help in extracting & displaying the error that results from an update (in case of failure).

In my case, the failures are usually the result of a validation rule, and I would like to display the Rule's error (and hopefully the rules name).

Event more optimistically, I would like the error to be displayed next to the field, as in theregular Salesforce behavior, but I don't know how to do that, so back to basics:


I'm using Ajax toolkit to update a field, I show the result in an Alert. I can see what looks like a class literal, it seems that I would like to extract the string called "message".


The relevent portion of the code is colored. 



{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")}var question = "You are about to ";if ( {!Timesheet__c.Inclusive_Rate_Validation_Override__c}) question+= "DISABLE";else question+= "ENABLE";question+= " manual override for this timesheet, \nAre you sure?"if (window.confirm(question)){ var timesheet= new sforce.SObject("Timesheet__c"); = '{!Timesheet__c.Id}'; timesheet.Inclusive_Rate_Validation_Override__c = {!NOT(Timesheet__c.Inclusive_Rate_Validation_Override__c )}; var connection = sforce.connection;sforce.connection.serverUrl = "/services/Soap/u/16.0"; var result; var callComplete = false; result = connection.update([timesheet]); if (result[0].getBoolean("success") ) window.parent.location.href="/{!Timesheet__c.Id}";else alert("Cannot Disable Manual Override, check that validation rules are held\n\nFailed to update Field with error: " +result[0]);}


 The result I get looks like the following (I think this is a javascript class literal). I would like to extract the message.


Cannot Disable Manual Override, check that validation rules are held Failed to update Field with error: {errors:{fields:'Standard_Inclusive_Rate__c', message:'Standard Inclusive rate must be in the range [6..25]', statusCode:'FIELD_CUSTOM_VALIDATION_EXCEPTION', }, id:null, success:'false', }


Thanks so much






Hi ,
Please try the following for extracting just the error message:-
Coming to your next requirement is to show the error similar to the Standard page, for that you can use a div at the top or in relation with each field and using appropriate logic display it in the div dynamically.


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.