function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VintaraVintara 

Silly question. Maximum records to be processed by a trigger is?

Its early and my espresso has not yet kicked in, so forgive me this rudimentary question. What is the maximum number of records that a trigger will process at once? Assuming some sort of bulk update, what is the most I can expect to see in the Trigger.new list? Trying to code around some potential governor limit issues.
Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

I am not going for any documentation right away, hope I will clear this on my own.

 

Trigger will be called when you perform any action on object record. Lets say I want to insert 50,000 records. I have a trigger in which some logic is written (may be some validations etc..).

 

Now there are different ways to insert records. I will go with data loader first. When I am inserting record with data loader then it insert the record in packets of 200 at a time. Means my trigger will be processing not more than 200 records.

 

Same case applies with batch class - maximum batch size can be 200. So here also my trigger will process not more than 200 records.

 

Now another way is to write an apex class which will insert records. As I have already mentioned that only 10,000 records will be processed at a time. So in this case my trigger will not be processing more than 10,000 records.

 

This flow is designed in a very smart way, that is why I love salesforce.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Ankit AroraAnkit Arora

Per my knowledge you can process (apply DML action) on 10,000 records at a time, no matter it is in trigger or apex class.

 

One more important point to remember :

 

If you use a non-selective query in a trigger against an object that contains more than 100000 records an error is generated. You should include indexed fields in the WHERE clause to avoid these exceptions.

 

You can find all limits here :

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

VintaraVintara
The issue is determining how many records will be processed in a DML statement within the trigger. If for each record in the "on update" trigger (Y), X additional records are inserted, I'm looking for Y to determine Y*X not to exceed 10,000. I seem to recall at one point there being a limit on the number of records processed by a trigger, meaning that Trigger.new will never be larger then a given value. But I'm not sure anymore.
Ankit AroraAnkit Arora

I am not going for any documentation right away, hope I will clear this on my own.

 

Trigger will be called when you perform any action on object record. Lets say I want to insert 50,000 records. I have a trigger in which some logic is written (may be some validations etc..).

 

Now there are different ways to insert records. I will go with data loader first. When I am inserting record with data loader then it insert the record in packets of 200 at a time. Means my trigger will be processing not more than 200 records.

 

Same case applies with batch class - maximum batch size can be 200. So here also my trigger will process not more than 200 records.

 

Now another way is to write an apex class which will insert records. As I have already mentioned that only 10,000 records will be processed at a time. So in this case my trigger will not be processing more than 10,000 records.

 

This flow is designed in a very smart way, that is why I love salesforce.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
VintaraVintara
So it sounds like the answer is "up to 10,000". Ugh, guess I just need to tell the users to not do that. Not that its likely to happen. I just hate having potential failure modes out there.
tauhakatauhaka

I think even when using bulk load with 10,000 record, which is the max for now, still Salesfroce processes only 200 at a time, so the tigger.size will not be greater than 200.

 

Willem MulderWillem Mulder
From the Bulk Apex Triggers Trailhead page: 

"Triggers execute on batches of 200 records at a time. So if 400 records cause a trigger to fire, the trigger fires twice, once for each 200 records." 

So it's never more than 200 records at a time. You're correct @tauhaka.
Monalisa Das 39Monalisa Das 39
I just wrote the following code in after insert trigger for Account and I found that the trigger is called exactly 50 times with trigger size of 200.
System.debug('--------------  Trigger called');
    System.debug('-- Trigger size : '+trigger.size);
    System.debug('-- Trigger new size : '+trigger.new.size());
I added 10000 account records from execute anonymous block to see the effect