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
eyekameyeyekamey 

How to process 100k records in Apex class

Hello, I have a requirement to build a lightning component to allow users upload csv files. These files have 100k rows and multiple users can upload large files at the same time. It's possible to have 15 files uploaded at the same time each with 100k rows. I need to have an apex class that processes these files and creates either leads or contacts from the rows based on some business logic. 
My first thought was to run an apex batch to process the files, but only up to 5 queued or active batch jobs are allowed. Any thoughts or recommendations? Thanks in advance!
AbhishekAbhishek (Salesforce Developers) 
Hi,

Your query is answered in the below blogs,

https://developer.salesforce.com/forums/?id=906F0000000AjuVIAS

https://www.solunus.com/apex-best-practices

https://salesforce.stackexchange.com/questions/60121/best-way-to-schedule-update-of-100k-records

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

Thanks.
eyekameyeyekamey
but I cannot have more than 5 active batch jobs. I might have 15 files at the same time that need to be processed and if I fire an apex batch for each file to process 100k records, my 6th file will fail and hit the limit. 
SUCHARITA MONDALSUCHARITA MONDAL
Hi eyekamey,

Try using Apex Flex Queue.   

Thanks,
Sucharita