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
NashornNashorn 

a problem I have since SOQL lacks ORDER BY

I am developing an S-Control using the AJAX API. I have a problem that pertains to sorting a SOQL result set. With normal SQL you can just use ORDER BY, but not with SOQL. As a consequence, I have to load every single data record with Javascript and then sort it. But all that I want is a subset of the data, e.g records 150 to 250 from the result set (but remember, I want records 150 to 250 from the complete _sorted_ result set). The problem occurs when I load all of the data at one time with Javascript in order to sort it. The browser starts to perform poorly and sometimes shuts down the script because too much memory is being used. Is there any way around this sorting problem?


More concretely, here is what I am doing:


//get all Contact ids (for an Account, for example)
var queryString="Select ContactId From Account where AccountId = 'xBLAHBLAH'";
var queryResult=sforceClient.Query(queryString);


//code left out for brevity:
     //get all results using queryResult = sforceClient.QueryMore(queryResult.queryLocator)
     //while doing this use queryResult[i].get("ContactID") to store all contact ids in an array named ContactIds


//so at this point we have thousands of contact ids stored in an array named ContactIds


// Now what I want to do is have the data sorted, and then get only part of it, such as records 150 to 250, from 1000 total records.
// If SOQL had ORDER BY, the records would already be sorted, and I would make the following call, using a subset of ContactIds from index 150 to 250
// ie ContactIds.slice(150,250)


ContactRecords = sforceClient.Retrieve("Salutation, LastName, FirstName, AccountId, Email", "Contact", ContactIds.slice(150,250));


// But since SOQL does not have ORDER BY, I have to load every single record, sort them, and then pick out the subset of indexes 150 to 250.
// Loading thousands of records in order to sort them uses too much memory.


 


I hope that the problem is clear, and thanks for any help.


If there is no solution, then I'll just have to forget about sorting the data.

Message Edited by Nashorn on 12-02-2005 02:01 AM

DevAngelDevAngel
Yup, message is very clear. Two things. First, order by is on the roadmap. This is absolutely critical for scontrols that use the AJAX toolkit especially for handling paging uis.

Second, even with order by, you have to be cautious when using the AJAX toolkit for thousands of records. The browser is just not well suited for that kind of memory requirement.

Message Edited by adamg on 12-02-2005 09:11 AM

johndesantiagojohndesantiago
I am having a similar issue when using Ajax to load a large number of records. I am planning on scaling that back but the issue that I noticed when I run my query once that returns say 1000 records it works fine. If I run that same exact query right after loading those records I get a memory error. It seems as if the data is still in memory after the page is loaded and my next query just adds to that.

Is this true and is there a way for me to clear the memory I am using right after querying?