3

When I go through the Salesforce developer interview questions, I have got this one:

What’s the maximum batch size in a single trigger execution?

Well, I don't know the answer of this one. And I don't even know what is batch size. So I googled about it. And see the following document: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_changing_batch_size.htm

In it:

You can change the batch size (the number of rows that are returned in the query result object) that’s returned in a query() or queryMore() call from the default 500 rows.

The maximum batch size is 2,000 records

The batch size will be no more than 200 if the SOQL statement selects two or more custom fields of type long text. This is to prevent large SOAP messages from being returned.

So according to this document, it seems to me the default number of rows returned in a SOQL call is 500 and the maximum we can set is 2000. However, I do remember I have queried more than that number before (maybe I remembered wrong?)

Is that limit still there? And is it only for triggers or for everything?

4

You're confusing queries for DML operations. DML operations are always batched to sizes of 200 records maximum (100 if it's a really old API version, for backwards compatibility reasons). The 200/500/2000 row limit applies to the size of a single query result without using queryMore.

See Triggers where they discuss this "batch size" in regards to older API versions:

In API version 20.0 and earlier, if a Bulk API request causes a trigger to fire, each chunk of 200 records for the trigger to process is split into chunks of 100 records. In Salesforce API version 21.0 and later, no further splits of API chunks occur. If a Bulk API request causes a trigger to fire multiple times for chunks of 200 records, governor limits are reset between these trigger invocations for the same HTTP request.

I can't seem to find the documentation that states that triggers execute in chunks of 200 records, but you'll notice that it's pretty much in all the official (and unofficial) literature out there.

| improve this answer | |
  • I am a little confused here. Does batch size in trigger mean the size of Trigger.New, or any SOQL return rows size? – Lance Shi Oct 5 '16 at 23:49
  • @LanceShi Trigger.new.size() will be at most 200; this is what they were asking about. Queries are various sizes from a few hundred to a couple thousand, based on the preferred batch size header, number and types of fields returned, etc. – sfdcfox Oct 6 '16 at 0:29
  • Thanks. I think it makes sense now. BTW, is the best way to contact you is via brian.m.fear@gmail.com ? – Lance Shi Oct 6 '16 at 0:33
  • @LanceShi yes. I'm at dreamforce right now, so I'm not terribly responsive at the moment, but please do feel free to contact me at that address. – sfdcfox Oct 6 '16 at 1:06
3

It is worth noting that for Platform Event subscribing triggers, at least as of Spring 19, the maximum trigger batch (chunk) size (Trigger.new) is 2,000

An extensive thread on this topic can be found with the Platform Events PM on the Platform Events Success Community courtesy of our own @DanielBallinger

Just to clarify, I've got the following trigger to go with the anonymous Apex from the original question. I'm getting debugs for Trigger.New.size() up to 300.

So the optimistic tuning can allow the processor to run on more than 200 events in a single transaction?

I could see sizes greater than 200 catching people out.

... Is there an upper bound on the Trigger.New.size() that could occur? I'll need to test that Platform Event triggers are sufficiently bulkified.


trigger TestEventTrigger on TestEvent__e (after insert) {
   System.debug('Size: ' + Trigger.New.size());
}

and the response from the PM:

Jay Hurst (Salesforce)

Up to 2000

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