Salesforce Developer Soql Versus Sosl


SOQL abbreviates for Salesforce Object Query Language.  SOQL is similar to the 
SELECT statement in SQL, but is designed specifically for Salesforce.

Use SOQL when you know which objects the data resides, and we want to:

1. Retrieve data from a single object or from multiple objects that are related 
   to one another.

2. Count the number of records that meet specific criteria.

3. Sort results as part of the query.

4. Retrieve data from number, date, or checkbox fields

SOSL abbreviate for Salesforce Object Search Language.  It is a full-text search 

Use SOSL when we do not need to know which objects or fields the data reside in, 
and we want to:

1. Retrieve data for a specific term that we know exists within a field.  
   Because SOSL can tokenize multiple terms within a field and build a search 
   index from this, SOSL search are faster and can return more relevant results.

2. Retrieve multiple objects and fields efficiently where the objects might or 
   might not be related to one another.

3. Retrieve data for a particular division in an organization using the division 

4. Retrieve data that is in Chinese, Japanese, Korean, or Thai.  Morphological 
   tokenization for CJKT terms.

Both SOQL WHERE filters and SOSL search queries can specify text we want to look 
for.  When we can use either language for a given search, SOSL is generally 
faster than SOQL if the search expression uses a CONTAINS term.

SOSL can tokenize multiple terms within a field (for example, multiple words 
separated by spaces) and build a search index.  If we are searching for a 
specific term that we know exists within a field, we might find SOSL is faster 
than SOQL.  For example, we might use SOSL if we were searching for John against 
fields that contains values like "Paul and John Company"

Keep the number of fields to be searched to a minimum.  Using a large number of 
fields leads to a large number of permutations, which can be difficult to tune.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License