2

In my Visualforce page, I am trying to retrieve all 884 records from a custom object (GeoPolygon__c). I have written the following SOQL query:

SELECT Id,Name,OwnerId,Owner_Name__c,Owner_Territory_Color__c,Country__c,Population__c,Land_Area__c,Population_Density__c,State__c,State_Code__c,JSON_Geometry__c FROM GeoPolygon__c

When executed in the Developer Console, all 884 records are retrieved. When executed in the Visualforce page, only the first 250 records are retrieved. The query is exactly the same. Here is the full line of code in the Visualforce page:

var geoPolygonQuery = sforce.connection.query("SELECT Id,Name,OwnerId,Owner_Name__c,Owner_Territory_Color__c,Country__c,Population__c,Land_Area__c,Population_Density__c,State__c,State_Code__c,JSON_Geometry__c FROM GeoPolygon__c");

The issue is definitely related to the fact that one of the fields in the query is a long text area field (JSON_Geometry__c). When I remove this field from the query, all 884 records are returned in both Developer Console and in the Visualforce page. When I include this field in the query, only the Developer Console returns all 884 records.

Here are the few similar cases that I was able to track down online:

https://success.salesforce.com/answers?id=90630000000gxRYAAY

https://developer.salesforce.com/forums/?id=906F000000090yKIAQ

SOSL query returns only 250 records even if there are more than 2000+ records present

I tried adding a WHERE clause to the query, as recommended by a few people, but the Visualforce page continues to return only the first 250 records.

How can I retrieve all 884 records? The long text area field must be included in the query. Thank you for any help!

6

The query is indeed returning 884 records, but not all at once. In the developer console, the query tab handles the work of retrieving all the records even when there are chunks. When you are doing it yourself in JavaScript, you should use the QueryResultIterator that's available in the AJAX Toolkit. The documentation includes an example:

var result = sforce.connection.query("select id, name from account"); 
var it = new sforce.QueryResultIterator(result);
while (it.hasNext()) { 
    var account = it.next();
    sforce.debug.log(account.Name); 
}
  • 1
    For anyone with a similar need, here was my final code based on sfdcfox's answer: var geoPolygonQuery = sforce.connection.query("SELECT Id,Name,OwnerId,Owner_Name__c,Owner_Territory_Color__c,Count‌​ry__c,Population__c,‌​Land_Area__c,Populat‌​ion_Density__c,State‌​__c,State_Code__c,JS‌​ON_Geometry__c FROM GeoPolygon__c ORDER BY Name"); var iteratedResult = new sforce.QueryResultIterator(geoPolygonQuery); while (iteratedResult.hasNext()) { var geoPolygonRecord = iteratedResult.next(); } – Scott Nov 6 '17 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.