Monday, 12 October 2015

Difference between database.insert and insert




* insert is the DML statement which is same as databse.insert.

* However, database.insert gives more flexibility like rollback, default assignment rules etc.

* We can achieve the database.insert behavior in insert by using the method    setOptions(Database.DMLOptions)

* Important Difference:

If we use the DML statement (insert), then in bulk operation if error occurs -
the execution will stop and Apex code throws an error which can be handled in try catch block.

If we use the DML database methods (Database.insert), then if error occurs
- the remaining records will be inserted / updated means partial DML operation will be done.

1 comment: