Trigger behaviour with insert and update in same execution context
Your trigger.isInsert and trigger.isUpdate blocks will be mutually exclusive as I understand it. (i.e. the insert and update operations will have independent execution contexts)
isInsert Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or the API.
It doesn't seem plausible for the value of Trigger.isInsert and Trigger.isUpdate to be true at the same time. Based on this, my understanding has been that a Trigger, even though both Update and Insert, will only get called for either of insert or update in a single execution context.
If you wanted to be transparent to the behaviour, you could use an upsert
, rather than an update
, which will cater for both Inserts and Updates. (Also as long as your insert / update behaviour is completely within the respective if blocks, it shouldn't really matter.)
its not documented anywhere but yes the list will initialized twice but they will still remain in same transaction and to add the governor limit will apply on the whole transaction not on each trigger events.
To try this out you can call insert a record from class and in the very second line try to update the record. Both insert and update event will fire in that transaction. First insert event will fire then again a update will follow the insert event.