- I know you must Bulkify your code.
- Does this mean you have to expect
UserInfo.getUserId()to be different users?
- I.E. Can the same trigger can be called on multiple records for multiple users in the same execution. Or will it always be the same user?
No. Every non-test transaction has exactly one context user. A trigger may be invoked with a set of records with different owners, but the context user for the transaction will be constant.
In a unit test context only, the running user may change in a
System.runAs() construct. This is not possible in normal Apex, though.
Platform Events triggers may receive events in a batch that were posted under different context users, but the trigger itself runs in the context of the Automated Process user for all of those events.
Other situations that appear to change context user, such as calling out to the Salesforce API through a Named Credential, really initiate a new transaction with a different context user.