• #61514
    Forcetalks

    What is the difference between insert() and database .insert() in salesforce ?

    Difference between insert() and database .insert()?

    #61516
    Salesforce | Laveena Laveena #3
    Forcetalks

    Hi Hariom,

    Insert:

    • 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.Insert:
    • 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.

    Thanks

    #61517
    Salesforce | Prachi Prachi #8
    Forcetalks

    Hi,

    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 DML database methods (Database.insert) used, then if error occurs the remaining records will be inserted / updated means partial DML operation will be done.

    Thanks.

     

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?