문제

How do I create a query in SOQL like:

SELECT Id FROM User WHERE rownum > 101 AND rownum < 200

I am trying to do pagination where I load the first 100, then if you click "Load more" I can query for the next 100.

도움이 되었습니까?

해결책

For the purposes of pagination, you would generally just make the whole query (which in your example would be just SELECT Id FROM User), setting the batch size to the size of your page, and then use queryMore() to get the next batch. This method does require you to store the QueryLocator from the QueryResult that you get from the initial query -- the sample code in the article I linked to above shows some good examples of it.

If you're doing this with a Visualforce page, you have another option -- SOQL also has an OFFSET clause that you can use to scroll to a specific row. Here's an article that describes it. Be careful though -- OFFSET is subject to some limitations that might hamstring you if users flip too many pages (see the SOSL and SOQL limits section of this page for specifics).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top