I need to write some trigger logic under EmailMessage. Out of habit and good coding practice, I did it is "bulkified".

However, an interesting thought came to me.

Do I really need to make it run in bulk? Will there be a scenario where EmailMessages come in bulk in a single transaction?

Does anyone know/tried to do this before?


There are a number of ways records can be inserted into objects. Use of DML via Apex through your own code is of course one. Here you can of course determine how many records are inserted at once. However the Force.com platform is a very open platform. There are numerous API's (Enterprise, Partner, REST) and also Data Loader tools (utilising these API's) that can also insert records into your objects on mass.

So the possibility still exists for bulk inserts, even if your code does not give rise to it. So as you say it is good practice, but if you have to consider avoiding bulkification you better be sure that all potential 'clients' of your object are not going to take any of these other routes and catch you out.

| improve this answer | |

Using the Email to Case Agent is an example where you'll need to have Bulkified code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.