Activity Forums Salesforce® Discussions Why we avoid DML query in "before" trigger in Salesforce?

  • Avnish Yadav

    Member
    July 5, 2018 at 5:39 am

    Hello Chanchal,

    In Before trigger, the records are not commited in database so we can skip the DML as whatever value we give to records will naturally assigned to database.

    Thanks.

  • madhulika shah

    Member
    September 10, 2018 at 1:11 pm

    Hi Chanchal,

    Before triggers are used to update or validate record values before they’re saved to the database. Avoid SOQL queries and DML inside for loops so that governor limit cannot be hit.

    Thanks.

  • shariq

    Member
    September 22, 2018 at 3:23 am

    Hi,

    In Before Triggers, actions are being performed before you commit the record to the database. This is where you usually do validations or updates to the same object. You can skip the DML operations here as whatever values you give in your code is automatically assigned to that record.

    Hope this helps.

  • William

    Member
    November 26, 2018 at 4:28 am

    Before triggers are used to perform the logic on the same object and it triggers fired before the data saved into the database. For DML operation it required to commit with data base. So, we cannot use the DML operation on these triggers.

    As per Order of execution before trigger fire and then after trigger fire.

    Before insert event

    Data committed to database

    After insert event

Log In to reply.

Popular Salesforce Blogs