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
Jamz_2010Jamz_2010 

Query Result Sets

Hi all,

 

Does anyone know if there is a way of bringing back sets of results in SOQL? For instance if I want to bring between the 20th and 50th rows back?

 

Thanks

 

James 

Best Answer chosen by Admin (Salesforce Developers) 
srisomsrisom

You could try creating a StandardSetController based on your query and call the previous() and next() methods to move through the set and getRecords() to get the next set back.  It won't be as flexible as you want (20th to 50th) would need a page size of 10 and lots of next calls.  Anyway thought I would mention it just in case.

 

 

All Answers

JimRaeJimRae

You have to create the subset yourself using a for loop.  This works fairly well, unless your primary set is larger than 1000 elements, which is the limit for a list.

 

I have done it like this:

 

 

List<Account> Accts = new List<Account>([select id,name from account limit 1000]); List<Account> p2Acct = new List<Account>(); for(Integer i=20;i<70;i++){ //pick records 20 through 50 in list p2acct.add(Accts[i]); }

 

 

 

srisomsrisom

You could try creating a StandardSetController based on your query and call the previous() and next() methods to move through the set and getRecords() to get the next set back.  It won't be as flexible as you want (20th to 50th) would need a page size of 10 and lots of next calls.  Anyway thought I would mention it just in case.

 

 

This was selected as the best answer
Jamz_2010Jamz_2010

Thanks, it didn't really fix the problem as I was trying to be cheeky and get around the 10,000 rows problem. I think I'll just have to find another way around.

 

Thanks Anyway

 

James