+ Start a Discussion

how can i split list into small lists


I have requriment like,

we have one LIST<> with having many records(records we be dynamic).if list having more then 200 records i wanted to split into 200 recards for each list and that list we wanted to send to  External system(each time 200 records).and we don`t want to use Bach Apex.

how can i archive this.please give me the solutions..


Thanks in Advance,




Hi Reddy,

Did you get any solution of this, since I also need to split one list into several smaller lists.



M K Lal (Mac)M K Lal (Mac)
Hi Reddy/Nikhil,

We can use custom code for split the list. 
for best reference/practice, here is the code

Suppose you want to spilt lists in max. 200 elements each (we can change dynamically)
            for(Integer i = 0 ; i < (lstEmployee.size() / 200)+1 ; i++){
                lstTemp = new List<Employee__c>();
                for(Integer j=(i*200);(j<(i*200)+200) && j<lstEmployee.size() ; j++){

lstEmployee: Your main list
lstTemp : Lists which will created from main list (say 1,2,3)
lstWrapper : List of all small lists (say 1,2,3)

manan patel 7manan patel 7
i split list in small and add it in master list but in the for loop it get soql 101 error
 for(integer j=0;j<lstWrapper.size();j++)
         for(Account acc:lstWrapper[j])
           trs= [SELECT Rev_Logis__c,Eval_Date__c FROM transaction__c where Related_Account__r.Name=:acc.Name];
its give me a error please help me.
M K Lal (Mac)M K Lal (Mac)
Hi Manan,

You are using SOQL in loop, this is the issue.
As salesforce has limitation for SOQL Queries (different with org type).
Alaways ignore SOQL in loop for best practice and quality code.

Eric Kramer 24Eric Kramer 24
Thanks so much for your example on splitting lists. It solved a problem I had been working on for weeks and put my project back on track. You are the best.