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
Nitin SehgalNitin Sehgal 

How to break a List<SObject> into multiple Lists?

Hi Everyone,

 

I have a problem, that is i have a List<SObject>, which contains more then 10000 records and i want to perform insert operation on that List but it hits the limit.

So, can anybody suggest me how can i break this list into multiple lists.

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

In that case I'd look to reduce the size of the scope for each batch transaction.  The default is 200, so if you are creating > 10k records from those, drop it down to 100.  I've had to reduce the batch size to 3 in the past due to the sheer number of post-processing that took place in triggers.  It runs slower, but it works.

All Answers

bob_buzzardbob_buzzard

Much depends on how you are constructing the list.  One way would be to use batch apex which breaks your processing up into a number of discrete transactions, allowing you to process 10k records per transaction.  

 

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

Nitin SehgalNitin Sehgal

Hi Bob,

 

Thanks for you help but i am I am inserting records from batch apex. What i am doing is getting some records and match with some other records and then if records dose not match then i create new records. I have a large no of records in my org. New inserting list have more then 10k records which is causing limit hit.

 

Please suggest somthing.

 

Thanks,

Nitin

bob_buzzardbob_buzzard

In that case I'd look to reduce the size of the scope for each batch transaction.  The default is 200, so if you are creating > 10k records from those, drop it down to 100.  I've had to reduce the batch size to 3 in the past due to the sheer number of post-processing that took place in triggers.  It runs slower, but it works.

This was selected as the best answer
Nitin SehgalNitin Sehgal

Thanks Rob.. :) It worked for me but it very taking a long time. Thanks a lot.