Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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 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.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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