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
Shailesh Patel 7Shailesh Patel 7 

DIVIDE List collection into sublist

i want to insert large number of records in Account Objects but as you know on salesforce governor limits is 10,000 records/DML so how can i divide list dynamic into sublist and is there any other way to insert list of records without exceed governor limits. i have been using batch class for it also. can you give me a sample code for my solution.
as per my knowledge there is a method for sublist in java but how can i do in apex?Please guide me.
Thanks in Advanced.
 
Daniel BallingerDaniel Ballinger
The limit (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm#transaction_gov_limits_section_title) of "10,000 Total number of records processed as a result of DML statements" is per-transaction. Even if you split the list, you wouldn't be able to process any more records in that transaction.

If you are in a batch context, try reducing the overall batch scope. It may get the number of records per execute down to a manageable level. Failing that, you may need to start a secondary batch job to process all the records that need to be updated.
Shailesh PatelShailesh Patel
okay, can you tell me how many records insert in single csv file using apex batch class?
Daniel BallingerDaniel Ballinger
I don't fully understand what you are trying to do. If you use the bulk API you can insert millions of Account records if that is your goal.

Do you have a CSV file that is being split and then processed by a batch job? Have a look at Importing large CSV files via Batch Apex (http://developer.financialforce.com/customizations/importing-large-csv-files-via-batch-apex/). The limiting factor here will be the Apex processing time and heap limits. After that you just adjust your batch scope size small enough so that you stay within the 10,000 records process within DML statements.