ONE DAY SALE

Free Salesforce Developers Tutorials >

Chapter 7 - SOSL >

Search Groups in SOSL | Return Specific Fields

Search Groups in SOSL | Return Specific Fields

What You’ll Learn


S2 Labs

What Is Search Groups in SOSL

Search Groups are basically used to define the type of fields in which you can search that text.

Search in Specific Fields:

  • All Fields (By Default)
  • Name Fields
  • Email Fields
  • Phone Fields
  • Sidebar Fields

Returning

If we want to return texts from a particular object then we use returning keyword.

Ex:

List<List<sObject>> results = [FIND 'Univ*' IN NAME FIELDS RETURNING Account, Contact];
List<Account> accounts = (List<Account>)results[0];
List<Contact> contacts = (List<Contact>)results[1];

Return Specified Fields

 If we want to search text in a particular field, we are going to use search group.

Find {contact} IN (searchgroup)

  • All Fields (By Default)
  • Name Fields
  • Email Fields
  • Phone Fields

Syntex :

Find {contact} IN (searchgroup) returning objects & fields.

Example :

List<List<sObject>> results = [FIND 'Univ*' IN NAME FIELDS RETURNING
Account(Name, BillingCountry), Contact(FirstName, LastName)];
List<Account> accounts = (List<Account>)results[0];
system.debug(accounts[0].Name);

Note:
  • Return Type of SOSL is list of list of sObjects which is parent class of all Objects.
  •  In Apex use ‘ ’ instead of { }.

 

LWC Training

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *