Notes :

  1. Apex Contains the built-in Database class which provides DML Operations.
  2. Syntax :
    1. Database.insert();
    2. Database.update();
    3. Database.upsert();
    4. Database.delete();
  3. Database class methods are static and are called by the class name.
  4. Database methods have an optional allOrNone parameter.
  5. This Parameter allows you to specify whether the operation should partially succeed.
  6. when the parameter is set to false, if error occurs on a partial set of records, then the successful records will be committed and errors will be returned for the failed records.
  7. No exceptions are thrown with the partial success option.
  8. This feature is not available with DML Statements.

Example

  1. Database.insert(recordList, false);
  2. The Database methods return objects containing success or failure information of each record.
  3. For Insert & Update operations an array of Database.SaveResult objects are returned.
  4. Database.SaveResult[] results = Database.insert( recordList, false );

Note

  1. If you want to prevent record to save then you can use addError() method;
  2. Database.UpsertResult[] results = Database.upsert( recordList, false) ;