How might one implement SOSL paging, i.e. get the next 200 results, in Apex?

  • 3
    I know this doesn't answer your question (hence I'm not writing it as an answer!) but I think Jeff Atwood hits the nail on the head when it comes to pagination: codinghorror.com/blog/2012/03/the-end-of-pagination.html Do you really expect your user to flick through more than 200 results? Your best option might be to suggest to the user that they refine their query, or increase granularity of the query parameters available to them. – Matt Lacey Aug 27 '12 at 3:32

These probably aren't the answers your looking for, but unless someone else has some clever ideas...

The current answer in the Force.com Discussion Boards : Pagination for SOSL query is:

"No, it's not possible to query more than 200 records in a SOSL query."

From SOSL Syntax

Syntax: LIMIT n

Description: Optional. Specifies the maximum number of rows returned in the text query, up to 200. If unspecified, the default is 200, the largest number of rows that can be returned.

IdeaExchange: Lift 200 record limit in SOSL

Update from Summer 2013 (API v28.0) Release Notes:

Increased Limit for SOSL Query Results
SOSL now supports up to 2000 results for each query instead of the previous limit of 200 results per query.

Increased Query Size Limit
The maximum size for a SOSL query has been increased to 20,000 characters.

| improve this answer | |
  • Hi @Daniel Is it still the same case or has anything been introduced in api 28.0 for Search more or find next set? I know there has been an increase in the results (2000) but is there an option for fetching next 2000 record set? Also can i find a string from all fields from all custom and standard objects and return the data (all field data) of all the records that matches for all the fields of those objects?? – Sathya Aug 6 '13 at 21:40
  • @Sathya I don't see any explicit paging support in the release notes. Your other question would be better suited to a separate Salesforce StackExchange question. – Daniel Ballinger Aug 6 '13 at 23:07
  • Thanks @Daniel here is the link to my question :- salesforce.stackexchange.com/questions/15149/… – Sathya Aug 7 '13 at 19:30

Use a WHERE (range) with an ORDER BY on the same column, and increase the WHERE on each page. General idea:

FIND {test}
RETURNING Account (id WHERE CreatedDate >= [last page's max createddate])
ORDER BY CreatedDate

Then you get the next 200 records, and the next paging click increments your search range criteria. It's not perfect but is a general pattern for getting around querying limits.

I somewhat agree with Lacey's reference to Atwood when it comes to building easy-to-use web software esp for B2C, but IMO there are plenty of valid use cases in business software for paging through 200+ records based on search/filter criteria.

| improve this answer | |

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.