What is bulkification and why is it critical in Apex triggers?
Suggested answer
Bulkification means writing code that handles up to 200 records in a trigger batch efficiently. Anti-patterns: SOQL inside a for loop (hits the 100 SOQL limit), DML inside a for loop (hits the 150 DML limit). Correct approach:
1. Collect all relevant IDs into a Set before the loop.
2. Query once outside the loop: Map<Id, Account> accMap = new Map<Id, Account>([SELECT Id, Name FROM Account WHERE Id IN :ids]);
3. Process records in the loop using the Map for O(1) lookups.
4. Collect updated records in a List.
5. Perform a single DML statement after the loop. This pattern works for any batch size and stays well within governor limits. Always test triggers with large data volumes (200+ records).
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.