+ Start a Discussion
Kelvin CheungKelvin Cheung 

Apex SOSL queries limited to 250 records per type

I'm running into some behavior with Apex SOSL queries in our managed package that I don't quite understand. Previously I was hitting a 200-record return limit on SOSL queries.  After realizing this limit was increased to 2000 in API version 28, I changed our API version to the latest (32). Now I'm seeing us hit a limit of 250 records per type.

For instance, with the query:
List<List<SObject>> searchList = [FIND 'com' IN ALL FIELDS RETURNING Lead(Id), Account(Id)];

Results seem to be capped at 250 Leads and 250 Accounts returned.  I can't find any documentation of such a limit.  The only thing I can find is a way to increase the batchSize in QueryOptions for API-based SOSL queries, but I can't see anything that applies to Apex.

Any help?  Thanks in advance!
Best Answer chosen by Kelvin Cheung
Kelvin CheungKelvin Cheung
Answered by Salesforce.com rep.  I'm not sure it's documented, but there is a 250 records per entity limit if you are querying multiple entities.

All Answers

PratikPratik (Salesforce Developers) 
Hi Kelvin,

What managed package you are using? 
As per governor limits, 2000 recodes (api version above 28) can be fetched through sosl query.

Thanks,
Pratik
Kelvin CheungKelvin Cheung
Pratik,

It's a managed package that my company is developing, but I'm running into the limit of 250 per record type not only in queries inside the managed package but also in the same code being run with Execute Anonymous in the Dev Console.
Kelvin CheungKelvin Cheung
Answered by Salesforce.com rep.  I'm not sure it's documented, but there is a 250 records per entity limit if you are querying multiple entities.
This was selected as the best answer
PratikPratik (Salesforce Developers) 
Hi Kelvin,

Thanks for the information. When you are not using the 'WHERE' clause the limit per entity becomes 250. 

Thanks,
Pratik
Daniel BallingerDaniel Ballinger
Oddly, I found that even just adding an ORDER BY to the SOSL will increase the limit from 250 to 2000 records. I'm not sure why this is the case, as SOSL Limits (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_limits.htm) puts the limit at 2,000 records from v28.0 onwards.

Reference SOSL query returns only 250 records even if there are more than 2000+ records present (http://salesforce.stackexchange.com/q/77110/102)
Anvesh SinghAnvesh Singh
@Daniel Ballinger's answer is very useful.
Thanks.