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
DMonsterDMonster 

System.IndexOutOfRangeException: Index was outside the bounds of the array.

The code below works fine using the development test account login. When I switch to the production login I get an error:
 
 qr = objSF.queryAll("select Id, Name, OwnerId from Opportunity");
for(int i=0; i < qr.size; i++)
                     {
                         sObject account = qr.records[i];
                         Response.Write("<br><br>Opportunity Name: " + getFieldValue("Name", account.Any) + "<br>Owner: " + getFieldValue("OwnerId", account.Any) + "<br>ID: " + getFieldValue("Id", account.Any));
                     }
 
I get this error:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
However, I just pull qr.records[5] or some other value it works. I noticed that using qr.records[qr.size] or qr.records[qr.size -1] also produces the error. It's like the size (qr.size) is not correct ; larger than it should be???
 
Any ideas? Again, works fine in development mode. Fails with production login.
 
 
SuperfellSuperfell
.Size returns the entire size of the query result, not just the size of this particular chunk, so if you have a query that returns 500,000 records, size will be 500000, but the records array will be no larger than 2000 items.
DMonsterDMonster

Thanks.. I figured it out from the API docs... Guess I shoulda checked there first.

 

Thanks,