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
Diogo MagalhãesDiogo Magalhães 

How can I filter a SOQL query by the object's row index when there isn't such column?

More specifically, I want to create various individual SELECT queries in which I retrieve the first 1000 results of the object, than the next 1000 and so on.
Example:
SELECT Id, Name FROM Account WHERE rowIndex BETWEEN 1 AND 1000;
SELECT Id, Name FROM Account WHERE rowIndex BETWEEN 1001 AND 2000;
(...)

The thing is, the column "rowIndex" (or an equivelent one) does not exist in the object (column "Id" does not qualify). 

So, how can I retrieve only 1000 results each time of the query: "SELECT Id, Name FROM Account"?

Thank you.
Neetu_BansalNeetu_Bansal
Hello Diogo,

For fetching records there is one inbuilt function i.e. OFFSET but it will work only for 2000 records. For more details refer to heading 'OFFSET' in the index in below pdf:
https://resources.docs.salesforce.com/sfdc/pdf/salesforce_soql_sosl.pdf

Example to use offset is:
Select Id, Name from Account limit 20 OFFSET 10;
The result set for the preceding example would be a subset of the full result set, returning rows 11 through 30 of the full set.

Please mark this as best answer if it helps.

Thanks,
Neetu
Diogo MagalhãesDiogo Magalhães
Hello Neetu,
Thanks for taking the time to answer.
I have around 100000 records and since OFFSET is limited to 2000 records, it won't work right?
Vijaya Kumar RegantiVijaya Kumar Reganti
HI Diogo Magalhães,

Why dont you raise a request to Salesforce to enable indexing on some field and then work using that field.

Best Regards,
Vijay