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?

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.

  • 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 Sep 4 '15 at 17:33

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.