Skip to main content
Added some information regarding the query
Source Link
Ramy
  • 61
  • 1
  • 2
  • 6

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records. First list should contain first 5000 records and second list should contain the next 5,000 records and so on.

The reason behind this: I want to pass each list of 5000 records to a queueable job or create three queueable jobs.

if(mainLst.size() > counter)
{
    List<Custom__C> newList = new List<Custom__C>();
    List<Custom__C> newList1 = new List<Custom__C>();
    List<Custom__C> newList2 = new List<Custom__C>();
    for(Integer i = 0; i< counter; i++)
    {
        newList1.add(mainLst[i]);
    }
    // Perform some operation with newList1    
    // Perform some operation with newList2 
    // Perform some operation with newList3                                   
}  

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records.

if(mainLst.size() > counter)
{
    List<Custom__C> newList = new List<Custom__C>();
    List<Custom__C> newList1 = new List<Custom__C>();
    List<Custom__C> newList2 = new List<Custom__C>();
    for(Integer i = 0; i< counter; i++)
    {
        newList1.add(mainLst[i]);
    }
    // Perform some operation with newList1    
    // Perform some operation with newList2 
    // Perform some operation with newList3                                   
}  

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records. First list should contain first 5000 records and second list should contain the next 5,000 records and so on.

The reason behind this: I want to pass each list of 5000 records to a queueable job or create three queueable jobs.

if(mainLst.size() > counter)
{
    List<Custom__C> newList = new List<Custom__C>();
    List<Custom__C> newList1 = new List<Custom__C>();
    List<Custom__C> newList2 = new List<Custom__C>();
    for(Integer i = 0; i< counter; i++)
    {
        newList1.add(mainLst[i]);
    }
    // Perform some operation with newList1    
    // Perform some operation with newList2 
    // Perform some operation with newList3                                   
}  
deleted 178 characters in body
Source Link

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records.

if(mainLst.size() > counter)
{
                List<Custom__C> newList = new List<Custom__C>();
                List<Custom__C> newList1 = new List<Custom__C>();
                List<Custom__C> newList2 = new List<Custom__C>();
                for(Integer i = 0; i< counter; i++)
                {
                       newList1.add(mainLst[i]);
                       

   
                }
                       // Perform some operation with newList1    
                       // Perform some operation with newList2 
                       // Perform some operation with newList3     
                                   
 }  

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records.

if(mainLst.size() > counter)
{
                List<Custom__C> newList = new List<Custom__C>();
                List<Custom__C> newList1 = new List<Custom__C>();
                List<Custom__C> newList2 = new List<Custom__C>();
                for(Integer i = 0; i< counter; i++)
                {
                       newList1.add(mainLst[i]);
                       

   
                }
                       // Perform some operation with newList1    
                       // Perform some operation with newList2 
                       // Perform some operation with newList3     
                                   
 }  

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records.

if(mainLst.size() > counter)
{
    List<Custom__C> newList = new List<Custom__C>();
    List<Custom__C> newList1 = new List<Custom__C>();
    List<Custom__C> newList2 = new List<Custom__C>();
    for(Integer i = 0; i< counter; i++)
    {
        newList1.add(mainLst[i]);
    }
    // Perform some operation with newList1    
    // Perform some operation with newList2 
    // Perform some operation with newList3                                   
}  
Source Link
Ramy
  • 61
  • 1
  • 2
  • 6

Apex - break list into multiple small lists before processing

I have a list of 15,000 records. I can maintain the count in a flag.

Integer Counter = 15000;

I want to break my main list into 3 small lists. Each list should contain 5,000 records.

if(mainLst.size() > counter)
{
                List<Custom__C> newList = new List<Custom__C>();
                List<Custom__C> newList1 = new List<Custom__C>();
                List<Custom__C> newList2 = new List<Custom__C>();
                for(Integer i = 0; i< counter; i++)
                {
                       newList1.add(mainLst[i]);
                       

   
                }
                       // Perform some operation with newList1    
                       // Perform some operation with newList2 
                       // Perform some operation with newList3     
                                   
 }