3

I am trying to implement pagination for SOSL search. It queries Accounts and Contacts. I thought of utilizing StandardSetController but it seems not possible with SOSL. Per documentation, SOSL can return only 2000 records across all objects included. Let us say my query returns 1000 records each for account and contact. I wanted to display only 50 records first and then when user clicks NEXT then fetch next 50 records. I did this using StandardSetController in a diffrent project but not using SOSL. Can you please give some insight?

1 Answer 1

5

As you've seen, you can't do this directly. You could, however, could choose to do this:

StandardSetController 
    accounts = new StandardSetController([FIND :term IN ALL FIELDS RETURNING Account(...)][0]),
    contacts = new StandardSetController([FIND :term IN ALL FIELDS RETURNING Contact(...)][0]);

Then, you could paginate both results independently. Alternatively, just concatenate the two lists together and pass that to the StandardSetController; it does accept just a plain SObject list.

1
  • Thanks for the insight. I wanted to keep accounts and contacts separate without combining as I am using separate visualforce tabs for displaying object results. As you mentioned, I might have to create a StandardSetController for each object.
    – sdondeti
    Commented Sep 4, 2015 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .