Please enable JavaScript.
Coggle requires JavaScript to display documents.
Trigger Design Patterns (One Trigger Per Object (One trigger is created on…
Trigger Design Patterns
One Trigger Per Object
One trigger is created on an object for all possible events
Multiple trigger can result in exceeding governor limits
Multiple triggers order of execution cannot be controlled
A class can store the logic for the trigger
Class logic can be reused elsewhere like VF pages or test classes
Allows controlling the order of execution
Avoids exceeding governor limits due to multiple triggers
Trigger Handler Class
Trigger delegates logic to a handler class
An Apex Trigger should be logic-less
Handler methods are created based on context
Routing logic using if else statements can be used
New functionality is added without modifying the trigger
Bulk Triggers
Sets and maps are used for bulk processing of records
Designed to process thousands of records at once
One DML statement is used for operations
A trigger designed to handle records in bulk should only use 1 DML statement
Designed to not exceed governor limits
Database Operations
Should be moved out of For loops
add records to a list for insert
Use a DML statement to insert a List of records in one operation.