Notes :
- Apex Contains the built-in Database class which provides DML Operations.
- Syntax :
- Database.insert();
- Database.update();
- Database.upsert();
- Database.delete();
- Database class methods are static and are called by the class name.
- Database methods have an optional allOrNone parameter.
- This Parameter allows you to specify whether the operation should partially succeed.
- 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.
- No exceptions are thrown with the partial success option.
- This feature is not available with DML Statements.
Example
- Database.insert(recordList, false);
- The Database methods return objects containing success or failure information of each record.
- For Insert & Update operations an array of Database.SaveResult objects are returned.
- Database.SaveResult[] results = Database.insert( recordList, false );
Note
- If you want to prevent record to save then you can use addError() method;
- Database.UpsertResult[] results = Database.upsert( recordList, false) ;