You need to sign in to do that
Don't have an account?
Olbrest
How can I make SOQL querry which selecting records from xx to yy ?
Hello.
I have the salesforce object with ~ 10000 records.
I need to select specific range of records.
For example records from 5000 to 5500.
In MySql I use next query: [ select id from object limit 5000, 500 ]
But I can't found the way how I can make it in Apex SOQL.
Thank you.
If you don't have any specific way of identifying the range on the record itself, some special exteral id field for example, you could use a for loop to do this.
List<mycustObj__c> rangerecs = new List<mycustObj__c>(); Integer rangecounter =0; for(mycustObj__c x : [select id from mycustObj limit 5500]){ if(rangecounter>=5000){ rangerecs.add(x); } rangecounter++; } system.debug('my list has this many records: '+rangerecs.size());
This will work if you need less than 1000 in your range (since a list can only contain 1000 elements).
You could also use a variation of this counter and for loop to do things without a list as well.
Be careful however, you will need to somehow limit your records being returned or you will hit a governor limit.
All Answers
If you don't have any specific way of identifying the range on the record itself, some special exteral id field for example, you could use a for loop to do this.
List<mycustObj__c> rangerecs = new List<mycustObj__c>(); Integer rangecounter =0; for(mycustObj__c x : [select id from mycustObj limit 5500]){ if(rangecounter>=5000){ rangerecs.add(x); } rangecounter++; } system.debug('my list has this many records: '+rangerecs.size());
This will work if you need less than 1000 in your range (since a list can only contain 1000 elements).
You could also use a variation of this counter and for loop to do things without a list as well.
Be careful however, you will need to somehow limit your records being returned or you will hit a governor limit.
Thank You.
Oh... I have over than 10000 records in object.
How can I select records from 10001 and following ?
( I'm using live account )
I think you are going to rethink your design then. Any SOQL query that returns more than 10000 records will cause an error, due to hitting the governor limit (too many query rows).
You will probably need to consider doing something like adding an additional field on the object record that you can use to number them and get the approporiate range of values back.
Good Luck!