Activity › Forums › Salesforce® Discussions › Why we avoid DML query in “before” trigger in Salesforce?
Tagged: Before Trigger, DML in Salesforce, DML query, Salesforce Apex Trigger, Salesforce Trigger, Triggers in Salesforce
-
Why we avoid DML query in “before” trigger in Salesforce?
Posted by chanchal kumar on July 4, 2018 at 2:19 PMWhy we avoid DML query in “before” trigger in Salesforce?
William replied 7 years, 5 months ago 5 Members · 4 Replies -
4 Replies
-
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.
- [adinserter block='9']
-
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.
-
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.
-
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.