You need to sign in to do that
Don't have an account?
System.TypeException: Cannot have more than 10 chunks in a single operation.
Hi Board,
I'm facing a issue in trigger where in i'm trying to perform a dml statement using List<sObject>.
It throws exception for me when i have more then 900 records in my list.
Error message is stated below:
System.TypeException: Cannot have more than 10 chunks in a single operation. Please rearrange the data to reduce chunking.
The order of the items seems to play a part in the 'chunking'. It chunks everytime you switch object types. If you are passing 12 items in a list of types A and B, this list contains 2 chunks:
A, A, A, A, A, A, B, B, B, B, B, B
But this list contains 12 chunks:
A, B, A, B, A, B, A, B, A, B, A, B
All Answers
Hello,
How many types of objects are you putting into the List?
If less than 10, then you should group them by type. (How? just create lists for each object, for example, and when you are done, loop over all the object-list adding them to the merged list).
If more than 10, consider performing more dmls operations, (one per each group of 10 different objects).
Regards. (I'm just guessing, hope this work)
Yup, i have 7 datatypes and they are added in any fashion to sObject list.
Actually I was trying to avoid the grouping as my business logic is so huge :-( . But atleast it will save dml statements so will give it a try.
Will mark the post resolved after trying. Thanks for some shedding lights over the exception :-)
Hi SeAlVa,
After debugging i noticed that the lists are already grouped according to Type and only are 7 in number but still facing same exception.
I fear that will have to use different instances of every list for performing DML. :(
I was facing the same issue when trying to update a list of SOBjects that contained 6 different objects.
The solution was to separate the objects into 2 lists of 3 and calling separate updates.
Yeah, I also implemented it in the similar way.
I had misunderstood exception messages as 10 chunks = 10 different types of objects in single list of sObject.
Still i'm not aware what exactly the exception message conveys.
The order of the items seems to play a part in the 'chunking'. It chunks everytime you switch object types. If you are passing 12 items in a list of types A and B, this list contains 2 chunks:
A, A, A, A, A, A, B, B, B, B, B, B
But this list contains 12 chunks:
A, B, A, B, A, B, A, B, A, B, A, B
Hello all,
A bit old topic, but I solved this using following util method. I think this should work, any remarks or tips about the code?
edited: added check for && !sortedMapPerObjectType.isEmpty()
I want to create insert an new list. If anybody knows how to do it.Please let me know
Thanks,
Below post resolved this issues.
http://bartoszborowiec.wordpress.com/2014/06/15/execution-failed-system-typeexception-cannot-have-more-than-10-chunks-in-a-single-operation-please-rearrange-the-data-to-reduce-chunking/
Thanks,
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_list_sorting_sobject.htm
Hello,
Jeeedeee's code is great but it misses a important scenario which generate chunk: If in your list of sObject you have more than 200 records of the same object it will generate one chunk per 200 records. E.g: you have 1600 A, 50 B, 50 C and 50 D you will reach 10 chunk limit even with 4 objects.
I modified a bit Jeeedeee's code to cover this use case:
It might not be the best optimization, I'm happy to take comments on this.
Hope it helps.