PDI · Question #143
The following automations already exist on the Account object: - A workflow rule that updates a field when a certain criteria is met - A custom validation on a field - A How that updates related conta
The correct answer is D. The trigger may fire multiple times during a transaction.. When testing an Account trigger, developers must consider that a single DML operation can cause the trigger to fire multiple times within a transaction due to subsequent record updates by other automations like workflow rules or flows.
Question
The following automations already exist on the Account object:
- A workflow rule that updates a field when a certain criteria is met
- A custom validation on a field
- A How that updates related contact records
A developer created a trigger on the Account object. What should the developer consider while testing the trigger code?
Options
- AThe flow may be launched multiple times.
- BWorkflow rules will fire only after the trigger has committed all DML operations to the database.
- CA workflow rule field update will cause the custom validation to run again.
- DThe trigger may fire multiple times during a transaction.
How the community answered
(49 responses)- A4% (2)
- B12% (6)
- C8% (4)
- D76% (37)
Why each option
When testing an Account trigger, developers must consider that a single DML operation can cause the trigger to fire multiple times within a transaction due to subsequent record updates by other automations like workflow rules or flows.
While a flow can be launched, the primary consideration for a trigger is its own re-execution due to platform automation, rather than the flow itself launching multiple times which is a separate behavior.
Workflow rules fire after `before` and `after` triggers and *before* committing all DML operations; their field updates can cause triggers to re-fire, not only after commitment.
A workflow rule field update can cause a validation rule to run again, but the question asks what the developer should consider while testing the *trigger code* itself, focusing on trigger behavior.
Due to Salesforce's order of execution, subsequent updates by workflow rules or flows within the same transaction can cause the initial trigger to fire again, which is crucial for developers to consider during testing to prevent unintended side effects.
Concept tested: Salesforce trigger order of execution
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
Topics
Community Discussion
No community discussion yet for this question.