What happens if you update a record and the update fails because you entered the wrong data? Yes, correct—you get an error message. But behind the scenes, this is what we developers call an exception.
In Salesforce, you have two big types of exceptions:
- Standard exceptions
- Custom exceptions
Standard exceptions are predefined in Salesforce. If you update a record and the update fails, you'll receive a DML exception. If a callout to a web service fails, you will receive a callout exception. You can find all types of standard exceptions in an overview at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_exception_methods.htm.
But how do we use the standard exceptions? Do you remember, in one of the first lessons of this book, the try...catch structure?
Yes, we try to execute some logic, and if the execution fails...