What is SOSL – Salesforce Object Search Language

SOSL – Salesforce Object Search Language

From our previous Salesforce Developer Tutorial we have clearly learned about Salesforce Object Query Language(SOQL). We all know that SOQL is the language which supports and designed for structured queries to retrieve all records and related objects with precised filtered conditions. In this Salesforce Developer Training tutorial we are going to learn everything about SOSL, How SOSL used in apex. So to get an  idea on SOSL read full article from beginning to ending.

What is SOSL ?

Full form for SOSL is Salesforce Object Search language. SOSL and SOQL are implemented in force.com to index Data automatically  either the data is structured or unstructured . Salesforce object Search Language is a for unstructured queries which is also called full-text search language.

When a keyword is entered to search across multiple fields and objects then SOQL query is applied with precised filtering conditions for appropriate result. we have to make a choice when to use SOQL and when to use SOSL depending upon the objects. If we are required to search for a word  with in many string fields there we go for SOSL rather than SOQL. It is better to use SOQL queries for single objects to filter various data types.

Salesforce Object Search Language , SOSL Basics

 SOSL Basics

SOSL Basics

As already mentioned about SOSL that it is designed for Searching terms and scopes across multiple fields , strings and objects. We have a doubt that what is the form of a search term or how to search for a certain keyword in SOSL queries. In SOSL search terms are the “list  of string literals and wildcards”. Search Scope for any keyword in SOSL is the fields containing string data from one or another objects. We should not use check boxes, Numbers, Date fields in SOSL queries.

SOSL Query Syntax:-

  • FIND {SearchQuery}[In Search group ][Returning field Specification] [ record Limit].

SOSL syntax consists of four parts namely.

  1. Search Query.
  2. Search Group.
  3. Returning field specification.
  4. Record Limit.

Search Group :- In search group we have to enter the keyword or phrase with one or more words which can contain wildcards like * and also single characters like ?.These characters can be included in middle or ending of the search term. We have to enclose the term with Quotation marks ” “.  To Search for for a word or for a phrase we can use logical operators like AND, OR and AND NOT. Search terms are not case sensitive.

Search Group :- This Search group is optional we may use or not. In this Search group we can use the following values ALL FIELDS like all sting field values, NAME FIELDS like standard Name fields, EMAIL FIELDS like fields values of types Email and PHONE FIELDS like field values of type Phone.

Field Specification :- Field specification is nothing but the comma separation list of objects to include in result.

Record Limit :- Maximum number of records returned by SOSL query by default with out providing any limit is 200 .

0 comments… add one

Leave a Comment

error: Content is protected !!