Batch Apex is probably your best solution. Here’s how Batch Apex works under the hood. The execution logic of the asynchronous apex code,batch class is called once for each batch of records you are processing. Read less