The most fundamental best practice for writing bulk-safe (scalable) Apex triggers is to avoid performing DML operations or SOQL queries inside of loops. Salesforce enforces a limit of 150 DML statements per transaction. If a trigger iterates through a list of 200 records and performs a delete or update inside that loop, the code will fail with a governor limit exception after the 150th record.
To make a trigger bulk-safe, developers must collect all records that need to be processed into a collection (such as a List or Map) and then perform a single DML operation on that entire collection outside of the loop (Option B). This consumes only one DML statement regardless of the number of records (up to the 10,000 row limit).
Option A is incorrect because LIMIT 50000 does not help with bulk safety; it just prevents a query from exceeding the SOQL row limit. Option C (using allOrNone=false) allows for partial success of a DML operation but does not inherently make a trigger bulk-safe if the calls are still made inside a loop. Option D is incorrect because moving DML to a future method is a way to handle callouts or long-running processes, but it is not a general requirement for trigger bulkification and can lead to reaching asynchronous limits if used incorrectly.
==========
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit