- August 23, 2019 at 5:24 am #61514
What is the difference between insert() and database .insert() in salesforce ?
Difference between insert() and database .insert()?August 23, 2019 at 5:31 am #61516Laveena #3
- Partial insert is not supported.
- Roll back is not supported.
- If we use the DML statement (Insert) in bulk operation, then if error occurs the execution will stop. In that case Apex code throws an error and none of the record will insert to the database.
- Database methods are static methods available in Database class.
- Partial insert is supported.
- Roll back is supported.
- Includes the optional allorNone parameters that defaults true.
- If we use DML database methods (Database.Insert) in bulk operation, then if error occurs the remaining records will be inserted/updated means partial DML operation will be done. The only record throwing an error will not be inserted/updated.
ThanksAugust 23, 2019 at 5:32 am #61517Prachi #8
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)
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 DML database methods (Database.insert) used, then if error occurs the remaining records will be inserted / updated means partial DML operation will be done.
Please Register to reply to this topic. /