I have an inventory input page that I am working on and I am running into an issue where I need to create more than 10k records. The problem here is that all the information needed is not stored in an object but captured on the web page. Inventory numbers are entered and difference calculations are done to determine how many records to create. A record is created for each number in between 2 numbers the user inputs. The case I just tried and hit the limitation on attempted to create 27,500 records.

I assumed that I could use Batch processing but I can only find information related to querying for records and the Start method needs to return a Database.QueryLocator object.

Another option I am considering is breaking the lists into chunks less than 10k per list and calling a series of future methods - this would allow me to insert 100k records. The information could be passed in as a JSON string and broken down on the otherside.

Is anyone aware of something else that I can use to insert this many records with information collected during one execution context?

1 Answer 1


You don't need to use a QueryLocator. For example, you could write it like this:

public class MakeRecords implements Database.Batchable<SObject> {
    SObject[] queue;
    public MakeRecords(SObject[] records) {
        queue = records;
    public static SObject[] start(Database.BatchableContext context) {
        return queue;
    public static void execute(Database.BatchableContext context, SObject[] records) {
        insert records;
    public void finish(Database.BatchableContext context) {

You could also have some wrapper class and iterate through those items, if that's easier to code. You could even have an array of JSON strings, and deserialize the strings in the execute method.

The only requirement is that your start method must finish in 10 minutes. Normally, this isn't a problem, but do keep in mind that non-QueryLocator implementations will be rather severely limited (5 million or so values instead of 50,000,000 records).

You could even perform the "calculations" you mentioned in the start method, and return the results from start.

Your Visualforce page can periodically poll the AsyncApexJob table by job ID to show the user a progress bar.

  • Wow I really like the option of having the visualforce page poll the AsyncApexJob table to show a progress bar. Just a quick question regarding the technologies necessary to accomplish this - would the polling process require some javascript timed actions to update the page or is there something with the Streaming API that is a better fit (if that is possible with the streaming API)? I really appreciate your responses!
    – Chris
    Apr 6, 2015 at 16:38
  • 1
    The streaming API is kind of annoying to work with. I'd just set up a remote action method that performs the query every ten seconds or so and updates a progress bar by JavaScript. If you want, though, you could build it 100% in Visualforce, too. Just set up an actionPoller element that calls an update function and a rerender attribute.
    – sfdcfox
    Apr 6, 2015 at 16:50

You must log in to answer this question.

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