function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RonMillerRonMiller 

Noob transaction boundary question - triggers, futures, DML

All,
Noob, untrained, in wolf territory. I have a question on triggers and transactions. I am looking at existing code so here's an example of what I need to understand:
1. trigger on case does a DML insert or update to a case comment inside the trigger code
2. there is also a trigger on the case comment and that does some DML 

Now I understand that the terms transaction and context are interchangeable. So my question is: Are #1 and #2 in the same transaction (thru the commit of #2)??? Or is the transaction boundary of #1 at some point in #2 before the commit of #2 occurs?

I am having a problem with callouts where triggers and handlers and a mix of furure and sync calls are made. I follow it all but I really need to understand where the boundary is. The code below from the SF docs suggests to be that the transaction (in my case) would include thru the commit of #2. But what bugs me on this is that I have read that trigger calls are batched by the system up to 200 calls.

"For example, consider the following chain of operations: a custom Apex Web service method causes a trigger to fire, which in turn calls a method in a class. In this case, all changes are committed to the database only after all operations in the transaction finish executing and don’t cause any errors. If an error occurs in any of the intermediate steps, all database changes are rolled back and the transaction isn’t committed."
Brian Cherry FWIBrian Cherry FWI
For each update from the originating transaction counts as a DML operation. If the other triggers fires off the other trigger, then the DMLs under that trigger count towards the 200. Generally you can just bulkify the triggers by adding the records to a list then once everything is processed, update the list which is just 1 DML.