Activity Forums Salesforce® Discussions What is the difference between database.insert and insert in Salesforce?

  • Manpreet

    Member
    April 13, 2017 at 4:16 pm

    Hi Saurabh,

    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 an error occurs, the execution will stop and Apex code throws an error which can be handled in a try-catch block.
    If DML database methods (Database.insert) used, then if an error occurs the remaining records will be inserted/updated means partial DML operation will be done.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos