Please help me this. I have a call to action in salesforce visual force page, that insert 16k records.

But as per salesforce Limitation, we can only update 10k Records in a DML Transaction

I divide the records into two Batch each of 8K

The first batch of the 8k insert

And the other batch of 8k is inserted through Future call

Error: CPU limit time Exceeded

I know many of you will give me the answer of Batch Class but I have a limitation of the user which is during batch if user clicks on cancel. if it's in the middle half of my record is inserted and mostly half or not.

  • 1
    What is the limitation on using Batch Apex? I do not follow.
    – David Reed
    Jul 10, 2019 at 11:53
  • The Limitation is I can't stick the user page during the batch class. I want the user to give the answer in very real time, it will take time, or what if the user aborts the operation
    – Malik
    Jul 10, 2019 at 11:59

1 Answer 1


It is extremely unlikely that you will be able to insert 8,000 records in a transaction, regardless of the DML row limit, because the CPU time limit will get you first, as you have observed.

I see only a small number of options here.

  1. Run an Apex batch job. You'll get a job Id when you enqueue it, and your front end can monitor the process of the job and report it back to the user if needed.
  2. Run a Queueable chain. Monitoring the progress of the whole operation will be more difficult.
  3. Orchestrate the whole process from the front end by having your Visualforce page make JavaScript remoting calls for each batch of 200 records as a separate transaction, tracking progress and state in-browser.

In any of these cases, you will have to be prepared to handle the possibility that your database is in an "in progress" state, with the data only partially generated and inserted. You cannot perform a real-time, atomic operation on that many rows using any Salesforce functionality (and note that your solution using a future method is not atomic!). Depending on the route you choose, you'll also have to address the possibility of the job being canceled or failing, or the user navigating away or closing the browser window.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .