Activity Forums Salesforce® Discussions How database methods different from DML statements in Salesforce?

  • Adam

    Member
    January 10, 2018 at 10:52 pm

    There are a number of small differences. But from my understanding using database methods allow you control over how Salesforce handles failures in a batch. By setting a parameter (allOrNone) on a number of methods to either true or false you control how it processes failures in the batch.

    So does it roll all records in the batch back or does it fail just the record in question. Check out https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database.htm

    I am sure there are a few other differences, but that is first to mind.

  • Archit

    Member
    January 11, 2018 at 3:05 am

    Hello Ankit,

    In Apex you can perform dml operation in two different ways:

    • DML statements
    • Database class methods

    For partial successful results you have a choice to opt database methods because through these, if any operation get halted due to any errors in between it can perform action on rest other records leaving behind those who has an errors. While in DML, it can either perform complete operation (if no errors) or if there is any error comes in between it halts a running operation and also rolled back the other records at where the operation has already performed.

    Hope this answer would be helpful!!

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos