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?
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(...)]), contacts = new StandardSetController([FIND :term IN ALL FIELDS RETURNING Contact(...)]);
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.