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
quietopusquietopus 

Trigger Inputs: How are they organized?

I have multiple specific questions of interest related to this post's main question (see title). I'm not sure that there are publicly available answers to these. If not, it would still be helpful to know which questions Salesforce explicitly (purposefully?) leaves unanswered.

 

First, I'll make my terminology explicit:

 

When I submit a large quantity of records for a single DML operation (e.g. through Apex or through the Web API), Salesforce divides the job into smaller groups of records (typically groups of 200 records) and hands each group the appropriate Triggers.

 

  • I shall refer to the larger, undivided list of records as the original list.
  • I shall refer to the smaller groups as Trigger Batches (not to be confused with Batches, as they relate to the Batchable interface).
  • When a Trigger Batch is passed into a single Trigger and the Trigger performs operations on the records in that Trigger Batch, I shall refer to this as a Trigger Batch Execution.

 

Now, the specific questions of interest:

 

  • Do Trigger Batch Executions always occur in the order implied by the original list? If not, under what conditions might they not?
  • Do the records within a Trigger Batch always appear in the same order implied by the original list? If not, under what conditions might they not?
  • If the original list contains multiple instances of the same record (as indicated by the record ID), can that record possibly occur multiple times within the same Trigger Batch? If so, which instance do Trigger.newMap and Trigger.oldMap return for that record's ID?
  • If the original list contains multiple instances of the same record (as indicated by the record ID), can that record possibly occur multiple times across multiple Trigger Batches for the same original list?
  • If one Trigger Batch Execution makes changes to a record by changing its Trigger.new instance, are those changes visible to subsequently run Trigger Batch Executions? If both yes and no, what conditions determine whether yes or no?
  • If one Trigger Batch Execution makes changes to the Database via DML operations, are those changes visible to subsequently run Trigger Batch Executions? If both yes and no, what conditions determine whether yes or no?