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
Sam KamenskySam Kamensky 

What does the documentation mean to mark "a record with a custom error"?

For example:

For the sObject method addError(errorMsg) the documentation says to mark "a record with a custom error message and prevents any DML operation from occurring."

Does that mean the system will mark internally that a record occurred, and a developer can search for these errors later on?
Or does it mean that the error will be available for the duration of the transaction in which the marking of the error occured?

Seen Here:
https://developer.salesforce.com/docs/atlas.en-us.198.0.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_addError

Thank you
 
Best Answer chosen by Sam Kamensky
pconpcon
Both of the things you asked occur.  If you insert the object in something like a controller or another trigger the error will be thrown as a DML exception.  You can then catch that exception and handle it in your calling class.  If it remains uncaught then it will send an email to the person who deployed the code that started the whole transaction.  For example, if it was a trigger that started the whole thing an email would be sent to that developer.  If a Visualforce controller started the insert of the object that fails the email will go to the developer that deployed the controller.  The error will not be recorded anywhere outside of your standard debug logging mechanism (ie not stored on the record).

All Answers

pconpcon
Both of the things you asked occur.  If you insert the object in something like a controller or another trigger the error will be thrown as a DML exception.  You can then catch that exception and handle it in your calling class.  If it remains uncaught then it will send an email to the person who deployed the code that started the whole transaction.  For example, if it was a trigger that started the whole thing an email would be sent to that developer.  If a Visualforce controller started the insert of the object that fails the email will go to the developer that deployed the controller.  The error will not be recorded anywhere outside of your standard debug logging mechanism (ie not stored on the record).
This was selected as the best answer
Sam KamenskySam Kamensky
Thank pcon! 

"The error will not be recorded anywhere outside of your standard debug logging mechanism (ie not stored on the record)."

That line answered my question!