You need to sign in to do that
Don't have an account?
Shakena Watson
Apex Trigger to Process Bulk records
I will be calling an Apex process to update an object field (not a formula field) when there is an insert,
update or delete.
It will update the object field for all records in an object meeting an criteria, not just the records in the
trigger.new, trigger.old, etc., according to criteria.
Is a trigger the best place to call the process, since it is during a bulk up.
Should I be using something else (Flow, etc.).
I assume a trigger is the only way know if an object record is inserted into, updated, or deleted .
If a trigger is the route I need to take I need an example of how to call the process in an Apex trigger.
Thanks.
update or delete.
It will update the object field for all records in an object meeting an criteria, not just the records in the
trigger.new, trigger.old, etc., according to criteria.
Is a trigger the best place to call the process, since it is during a bulk up.
Should I be using something else (Flow, etc.).
I assume a trigger is the only way know if an object record is inserted into, updated, or deleted .
If a trigger is the route I need to take I need an example of how to call the process in an Apex trigger.
Thanks.
You can try using trigger and the advantage of bulkifying apex trigger is it can handle a large number of records efficiently.
Check below references that can help you.
https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_bulk#:~:text=Apex%20triggers%20are%20optimized%20to,likely%20to%20exceed%20platform%20limits.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_bestpract.htm
https://www.sfdc-lightning.com/2019/10/bulk-apex-triggers-in-salesforce.html
Thanks,
How is this a bulk trigger different then a regular trigger? In my company we are only allowed to use one trigger per object. Would this require me to create another trigger? I also noticed that the bulk trigger is using the trigger.new in the for loop (for a : trigger.new). As I mentioned in my email the calculation, on an object field, is not only performed on the records in the trigger.new, but all records according to a criteria.
Thanks.
Yes, it is best practice to have one trigger per object and you would need to create a new method in your handler class which will be invoked from trigger.
Something like below.
You might have a separate class to handle trigger variables, Kindly check your org trigger framework.
https://developer.salesforce.com/blogs/developer-relations/2011/04/apex-trigger-tip-using-a-class-per-object-to-control-logic.html
https://www.sfdcpanther.com/trigger-architecture-framework-recipe-sfdcpanther/
Thanks,