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
okaylah52okaylah52 

How to retrieve the error messages added using Sobject.addError()?

I have a list of SObjects. I pass the list to a utility method to check. In the method, it calls addError() of an SObject. How can I retrieve or go through the list and check which item has an error?

 

Thanks.

aalbertaalbert

The addError() method adds a custom error message to the specific SObject and prevents it from completing the DML operation. And the error message is returned to the user interface or API when the transaction completes. But there is no "getError()" method.

 

I think you can still accomplish your required error handling by re-factoring the code and how you identify errors.

okaylah52okaylah52

Thanks, Aalbert.

 

I am still curious. There must be a way to retrieve the error; otherwise, how can the user interface or API or the DML operation know that an error has occurred?

 

Anyway, I re-wrote my code to track and return 1st error encountered.