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
BOFHBOFH 

Extracting >2000 records

I am attempting to extract roughtly 4246 records from SalesForce.  I know the limit on the batch size is only 2000, which is where my problem comes in.  I get it to run through the loop 4246 times, but I end up with exactly 2246 null records.  I am not sure what I am doing wrong.  I have gone through the message board, but haven't been able to find much help, and staring at the code isn't working too well either.  So if anyone has any suggestions, they would be appreciated.  Below is the code I am using.  Thanks.

            binding.QueryOptionsValue.batchSize = 2000;
            binding.QueryOptionsValue.batchSizeSpecified = true;
            qr = binding.query("Select Id, OpportunityId, PricebookEntryId, Quantity, Option_id__c " +
                                          " FROM OpportunityLineItem WHERE Option_id__c <= \'0\'");
            done = false;
            if (qr.size > 0)
            {
                initializeArrays(qr.size);
                while (!done)
                {
                    for (int i = 0; i < qr.records.Length; i++)
                    {
                            sObject rec = qr.records[i];
                            id[i] = getValue("Id", rec.Any);
                            opportunityId[i] = getValue("OpportunityId", rec.Any);
                            priceBookId[i] = getValue("PriceBookEntryId", rec.Any);
                            quantity[i] = getValue("Quantity", rec.Any);
                            optionId[i] = getValue("Option_id__c", rec.Any);
                    }
                    if (qr.done)
                        done = true;
                    else
                        qr = binding.queryMore(qr.queryLocator);
                }
              }

Let me know if you need any more information.  Thanks again.
SuperfellSuperfell
Sounds like its not doing any of the queryMores, i'd step through it in a debugger or add a bunch of console.writeLines, so you can see which bits are getting executed.
BOFHBOFH
Can you possibly give me some more advice.  I stepped through the code, and it qr.records.length changes values every time the queryMore is run, but I am still getting null.  I'll keep looking around, to see if something jumps out at me, but at suggestions are still helpful, it looks like the queryMore is working, but I'm not positive.
Thanks.
SuperfellSuperfell
You reset 'i' each time around the while loop, so even after the queryMore, its just copying values to array indexes 0->2000 again.
BOFHBOFH
Yup, I noticed that right before checking your post.  Thanks for you help.