Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

2 Answers 2

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

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

 
discard

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.