Salesforce is stating in their documentation that all triggers are bulk triggers by default, see here
Here they state that a common development pitfall is the assumption that trigger invocations never include more than one record and that Apex triggers are optimized to operate in bulk, which, by definition, requires developers to write logic that supports bulk operations
It is of course best practice to bulkify all triggers, there is no question about this.
However ContentDocument and ContentDocumentLink triggers does not work in bulk mode which means the triggers are only invoked once even if you have 100 records in a transaction
This means that in email-to-case scenario if you have an email with 5 attachments first EmailMessage trigger is fired, then Case trigger, then ContentVersion 1 time and then ContentDocument and ContentDocumentLink 5 times each
If you have SOQL queries executed in ContentDocument and ContentDocumentLink trigger context you can reach the infamous “too many SOQL queries” very easily
I found that someone has noticed this as well: https://ideas.salesforce.com/s/idea/a0B8W00000GdpT7UAJ/bulkify-contentdocumentlink-trigger-in-case-of-emailtocase

Leave a comment