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
Dustin MayfieldDustin Mayfield 

Is it possible to split a list to only upsert 12 records at a time?

We have a visual force page that will upsert a list of records based on user input. Normally, users are only upserting 1 - 5 records, however, on ocassion there is a need to upsert 12+ records. In result, we are having another issue with a flow we have built that does a psuedo rollup summary to another object, and it is now hitting a recent update by Salesforce that limits record updates to only 12 in one call. We can't figure out how to optimize the flow to not hit the limits, so our best bet is to update how the upsert is done. I've partially adjusted our class to do the following:
 
try{
                if(tlToAdd.size() < 12) {
                	upsert tlToAdd;   
                    
                }
                else {
                   
                    
                    
                }
However i'm not sure how to complete the else statement. I'm not sure if there is a simple method to limit the upsert. Any thoughts?
 
Deepali KulshresthaDeepali Kulshrestha
Hi Dustin,


try{
   if(tlToAdd.size() < 12) {
       upsert tlToAdd;   
                    
   }
   else {
       // here you can create an another list of the object
        //  and run a loop on  the tlToAdd List add the item of the tlToAdd list in to the new List 
    // and also run a counter at each iteration 
    // after this check the value of the counter is whenever the value of counter is 12 upsert the list.
                
                    
   }

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha