You need to sign in to do that
Don't have an account?
Governor limits: 1,000 list elements and INSERTs
I understand the purpose of the governor limits. I understand some of the limits themselves, such as heap size. I do not understand many of them. One I do not understand is a limit of 1000 for a List. It appears to be an indirect memory limit, which is a duplicate effort since there is already a heap limit, and counterintuitive since one element can be as small as an Integer or as large as a complex blob containing object.
THE QUESTION: If I need to insert 1600 rows, does this actually mean I have to create two lists, one with 1000 and another with 600 rows, which I then have to execute as two inserts? Am I understanding this correctly?!?
All Answers
I agree the 1000 limit on collection is stupid. It would force us to write ugly code like use several lists, or lists of lists.
The "list" limit proportionally increases as the batch size increases. Meaning, if 50 records cause a trigger to initiate, the list limit increases to a max of 2000. Simply point it out - not saying it solves this specific issue.
Additionally, the insert DML operation only takes a max of 200 records at a time, so even with 1000 records, you would have to iterate across the set , for each 200.
To get higher limits and more flexibility, I recommend looking at Batch Apex.
aalbert,
It would appear code like this works for me. I don't have to iterate over it and break it into chunks of 200 for insertion.
List<Account> accts = new List<Account>();
for(Integer i = 0; i < 1000; i++){
accts.add(new Account(Name = 'test' + i));
}
insert accts;
Interesting - thanks for the correction. That code does run.
The apex docs seem to be misleading (link) where it says only a max of 200 sObjects can be passed into a single insert method. Or I didn't understand it properly. Nonetheless, I stand corrected.
At least I hope they are as we depend on the current behavior and changing that would not be good.
What is the correct answer to this? Is there a 1000 limit on lists or not?
I just ran this in the Execute Anonymous and it worked fine...
List<Integer> myList = new List<Integer>();
system.debug('Start');
for (Integer i = 0; i < 2000; i++){
myList.add(i);
}
system.debug('All Done');
Or is the limit more specific to sObjects or the number of objects that you can insert at a time?
Thanks!
and it seems like the limit is 10000 records at a time.
List<Attachment> atts = new List<Attachment>();
for(integer i=0;i<10001;i++)
{
Attachment objAttach = new Attachment();
objAttach.Name = 'testDemo'+i;
objAttach.contentType = 'text/plain';
objAttach.ParentId='00Q9000000rssuB';
objAttach.body = Blob.valueOf('attachment'+i);
atts.add(objAttach);
}
insert atts;
for the above code this below error occur
and when I canged the limit to 10000 its executed successfully.