Sample application to showcase how error handling can be done in a Salesforce app
Apex
Switch branches/tags
Nothing to show
Clone or download
Latest commit 1fa8823 Jan 15, 2014
Permalink
Failed to load latest commit information.
src Test to verify behavior of Database.insert. Jan 14, 2014
README.md Info added to readme file. Jan 14, 2014

README.md

Error_Handling

Sample application to showcase how error handling can be done in a Salesforce app.

DML Options

We wanted to compare the outcome when DML was performed in these three different ways:

  • Simple DML not contained in a try-catch
  • Simple DML wrapped in a try-cach
  • DML Performed through the Database class

Tests Purpose

The purpose of the following tests is to allow us to inspect the Database.SaveResult records and see other relevant information through the Debug statements in the error log:

  • SimpleInsertWithCatch_TEST
  • SimpleUpdateWithCatch_TEST
  • DatabaseInsert_TEST
  • SimpleUpdateWithCatch_TEST

All these tests use the Helper class, where the two most interesting pieces are the ones that associate an error with the record that caused it. This happens in the following places:

  • In the catch blocks if we made a simple Dml (not using the Database class)
  • In the processDml method is we performed the Dml through the Database class

The tests that verifies those pieces of code are working properly are in the AddError_TEST class.

Visualforce Page Purpose

The VisualForce page (Test1.page) allows us to see how the error message that we manually put inside the SObject using addError is displayed by default in the apex:pageMessages element. Also, we were able to test that no error message is shown in this element if we use the Database dml methods but don't manually add the error message to the object.

Database.insert Rollbacks

The DML methods of the Database class have very interesting behavior. They will roll back for certain types of errors, and then run again with only those records that did not fail in the first try.

For example of how Database.insert behaves look at the tests in the ERR_Handler_TEST class.