Because our client has a LOT of records (I have no idea how much), my colleagues feel it is necessary to use a SOSL query rather than a SOQL query, but I've never heard anything suggesting that SOSL should be more capable in such situations.

Is this true?

If so, at what point would there be too many records for SOQL?


It is incorrect to assume that SOSL is better for large data sets. Both SOQL and SOSL can be used with large data sets when implemented correctly.

I wrote an article (originally posted as a Q&A here) about the differences between SOQL and SOSL you may find useful. SOSL actually limits you to 200 records returned in a single SOSL query while SOQL will allow up to 50,000. On top of that, SOSL only allows 20 queries per request while SOQL allows 100.

When working with large data, your best bet would be to understand proper data structure and proper techniques (skinny tables, indexes, etc). Salesforce recommends the following when it comes to large data sets:

Use SOQL when

  • You know in which objects or fields the data resides.
  • You want to retrieve data from a single object or from multiple objects that are related to one another.
  • You want to count the number of records that meet specified criteria.
  • You want to sort results as part of the query.
  • You want to retrieve data from number, date, or checkbox fields.

Use SOSL when

  • You don't know in which object or field the data resides and you want to find it in the most efficient way possible.
  • You want to retrieve multiple objects and fields efficiently, and the objects may or may not be related to one another.
  • You want to retrieve data for a particular division in an organization using the divisions feature, and you want to find it in the most efficient way possible.
  • You beat me. Ah well, your answer looks better than mine would have been anyways.
    – sfdcfox
    Dec 5 '13 at 14:25
  • Excellent answer. Wish I could vote more than once for it. Dec 5 '13 at 14:36
  • Cheers for the awesome answer! Dec 5 '13 at 17:49

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.