 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. This is my website where you can find all videos created by me on Salesforce. In this video, I'm going to demonstrate and discuss about SOSL that is available in Apex. So first of all, let's understand the introduction of SOSL. So it stands for Salesforce Object Search Language. So we have one more entity that is SOQL. So that is for query language and SOSL is for Salesforce Object Search Language. So it is used to perform text search in records, then use SOSL to search fields across multiple SOSL records. So if we want to search multiple SOSL records, then we use this SOSL. Then for the last point says use SOQL to retrieve records for a single object, whereas you can use SOSL to search fields across multiple objects. So this is the basic difference between SOQL and SOSL. Now this is a syntax for SOSL. So you need to write find then the search query that you want to search. Then here we write search group and then we need to mention objects and fields in those we want to search a particular search query, right? So now the explanation. So in search query, that is this option. So we can put single word. So it should be enclosed in single quotes. And if you are having a phrase that is having multiple words, so you can, you need to enclose it in double quotes. Then search group. So it is basically optional. So if you don't provide any search group, so by default it will be all fields. Then here you can see the list of available search groups that you can use. So all fields name, email phone and sidebar. Then last is objects and fields. So this is also optional. It is the information to return the search result. So it returns a list of one or more S objects. So it depends upon how many objects or you can say in how many objects you want to apply your SOSL query. And within each S object list of one or more fields, then with optional values to filter again, so you can apply filters as well. Then if not specified, the search will contain the IDs of all objects found. So now after understanding the syntax, so this is the basic example of SOSL. So if you are applying SOSL on multiple objects, so we need to create a variable of type list of list and data type, we are using S objects, so further we will be typecasting it. Then search list will be storing the results. So find cloud in all fields returning. So account is S object. So we need to search its name field only. In this context, we want to search cloud in first name, last name and email. So wherever it is available, so all those records will be stored in this list of list S object. So now I am moving here. So in this anonymous window, I am going to create this list of list S object. So here I am writing Sanjay because account and contact, various account and contact records contain this word. So in all fields returning, then we have account, name, contact, first name, last name and email. And at last we have square with it. So we need to start it from here and it will end here and semicolon. So all the values, sorry, all the records on account and contact in these fields name, first name, last name and email if Sanjay is available. So those records will be available in the search list. Now we need to create list of, sorry, list of account, ACC list equals to new list of account, then list of, on list equals to list of contact. Now we can store the results in these lists. So ACC list equals to, and here we need to typecast as well. So on 0th index, this search list will be containing list of account, right? So I can write this. So on search list, zero index, we will be having account list because we are first searching in account and then we are searching in contact. So that the zero index list will be typecasted into list of account. Why so? Because here you can see we are using data type as S object, that is generic data type, right? So generic as object we are using. So we are typecasting it into a specific one. And then on list equals to list of contact and search list. And here I am passing index number one. Now to print the values we can iterate for loop. So count ACC, ACC list. So here I can write system dot debug. So ACC dot name. So this way account names will be displayed. Then I am implementing one more loop for contact list. So here let's say I am writing system dot debug, then con dot first name plus then space, then again plus con dot last name. So this way these lists will be displayed on debug log. So I am going to execute this. Okay. There are some errors there. This is unnecessary. So now I am going to execute this. So I am clicking on debug only. So here you will see the results. So this is for account name equals to the Sanjay Gupta Tech School. Then here you can see all the contacts. So here you can see test user, test user are available. So we are displaying name. So their email IDs are containing Sanjay as text. So that's why these details are available. So don't think like why it is printing. So because we are putting email as well here. So email will be hers and then this will be displayed. Right. So later on what you can do, you can apply. Let's say limit as well here. So if I agree with this again, so only two contacts will be displayed. So this way you can apply filters as well. So see only two contacts are displayed. Right. So optionally you can apply those things. So you can apply a very close as well. You can group you can apply group by as well. So by providing space after the fees you can apply the very close. So so that you can minimize the your searching for the objects. And here you can see if you want to apply this query query editor. So that is also possible. So I'm fetching this. And so from here I'm fetching this query data and pasting the square removing this limit so that we can have more records and instead of single quotes need to apply this career base here. And click on execute. So here you can see in search results, two tabs are available. One is for account. So come name is displayed. And this is for content. So here you can see first name, last name and emails are available. Right. So if I minimize this now. So in previous execution you saw this is this was showing test users. So here you can see in emails and jays available. And for this test user to also an email. So wherever in the fields specified in the query Sanjay word is available. So those records are queried and they are displayed here. So this way you can apply. So SL in a picks to search within multiple objects in various fields so that you can have a records of multiple objects. So I hope you understood how we can use SL SL in a picks and SOQL can be applied on one object whereas SL SL can be applied on multiple objects. And this is my website. So where you can watch various videos related to Salesforce. So all those links are available. Those videos are created by me. So visit this website and thank you for watching this video.