PDI · Question #227
A developer deployed a trigger to update the status__c of Assets related to an Account when the Account''s status changes and a nightly integration that updates Accounts in bulk has started to fail wi
The correct answer is A. Change the gerAssetsToUpdac= method to process all Accounts in one call and call it outside of. The issue is a trigger updating related Assets from Account changes, causing governor limit failures during bulk Account updates; the solution requires asynchronous processing.
Question
A developer deployed a trigger to update the status__c of Assets related to an Account when the Account''s status changes and a nightly integration that updates Accounts in bulk has started to fail with limit failures. What should the developer change about the code to address the failure while still having the code update all of the Assets correctly?
Exhibit
Options
- AChange the gerAssetsToUpdac= method to process all Accounts in one call and call it outside of
- BAdd a LIMIT clause to the SOQL query on line 16 to limit the number of Assets queried for an
- CMove all of the logic to a Queueable class that queries for and updates the Assets and call it from
- DAdd List<Asset> assets = [SELECT Id, Status__c FROM Asset WHERE AccountId = :acctId] to
How the community answered
(45 responses)- A76% (34)
- B4% (2)
- C4% (2)
- D16% (7)
Why each option
The issue is a trigger updating related Assets from Account changes, causing governor limit failures during bulk Account updates; the solution requires asynchronous processing.
Adding a LIMIT clause would prevent the trigger from updating all related Assets, which contradicts the requirement to update 'all of the Assets correctly'.
Placing a SOQL query inside a loop (implied by iterating over accounts and querying for each `:acctId`) is a common anti-pattern that leads to governor limit failures during bulk processing.
Concept tested: Asynchronous Apex for bulk processing and governor limits
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Topics
Community Discussion
No community discussion yet for this question.
