Salesforce Object Query Language | OnlineITGuru
Click to rate this post!
[Total: 0 Average: 0]

SOQL is used to make text-based Search Queries, on the search index SOSL. It is a search particular string from many objects. Every time it returns a list object. The output lists are every time return in the same sequence, as they were selected, in the SOSL query.

SOSL is like SOQL, but it searches records from many objects. That we can see in many objects, at the same time using SOSL. In SOSL, we can Query only a single object at a time, but in SOSL, the statements can not exceed more than 10,000 characters.

Know more about SOQL by Salesforce Online Training

1.SOSL Query starts with a keyword known as ‘FIND”.

2. At the same time, we can search a certain string like “US GLOBAL” in many objects.

3. It searches Record from Entire Database.

4. The result of SOSL is a sequence of sobjects “List<List<subject>>”

5. The changed result has a sequence of sobjects, in the same sequence as mentioned in SOSL Query.

6. If the SOSL query doesn’t return any records, for a significant subject type, then the search output includes an empty sequence for that subject.

7. The search string is of two characters long.

8. You can search text, phone, email, and multiple objects.

9. The maximum batch storage is 2,000 records. REST Calls or SOAP, apex statements, getter methods, visual force controllers, schema explorer for the eclipse toolkit.

1.Salesforce Object Query language(SOQL):

A SOQL query is equal to SELECT SQL statement and identifies the org database. SOSL is a scripted way of operating a text-dependent search on the search index. Whether you use SOQL or SOSL depends on whether you know which objects you want to search.

What is SOQL in Salesforce?| OnlineITGuru

2. When we have to implement SOSL?

Use SOSL, when you do not know what object or in where the data resides.

Getting Data for certain terms, that you exist within a field. SOQL can search in a faster way and they can change to more relevant results.

It searches the search text efficiently from many objects, whether they referred to every other or not.

3.Operation Considerations:

When you search general search terms, they slow or they return as many as results they can. Implement the following clauses for defining efficient text searches.

1.RETURNING: It searches from those fields and objects that mentioned and changed the result.

2.OFFSET: It shows the search results on many pages.

3.LIMIT: It defines many numbers of rows that return.

4.IN: It limits that type of field for searching, that contains email, mobile, and name.

4. Where SOSL is Used?

1.If we don’t know in what objects the data is shown.

2. We can get many objects and fields values, that efficiently works when the objects may or may not refer to each other.

3. We can search only those fields, what data types in email, mobile, and text.

4. We can implement classes, but not the triggers.

5. We cannot operate DML operations on search output.

List<list<SObject>> accountSearchList =newList<List<SObject>>();
accountSearchList=[FIND {onlineITGuru}IN Name Fields RETURNING
lead (name, phone Where created date = THIS_FISCAL_QUARTERLIMIT 20) ];
list<lead > accs;

Example of  SOSL
Apex class
Public with sharing class SOSLdemoExample{
Public List<Opportunity> optyList {get;set;}
Public List<contact> conList{get;set;}
Public List<account> accList{get;set;}
Public String searchStr{get;set;}
Public SOSLdemoExample(){
Public void soslSearchmethod (){
optyList = New List<Opportunity>();
conList = New List<contact>();
accList = New List<account>();
if(searchStr.length() > 2){
String searchStr1 = '*'+searchStr+'*';
String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS 

List<List <sObject>> searchList = search.query(searchQuery);
accList = ((List<Account>)searchList[0]);
conList  = ((List<contact>)searchList[1]);
optyList = ((List<Opportunity>)searchList[2]);
if(accList.size() == 0 && conList.size() == 0 && optyList.size() == 0){
apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sory, no results returned with matching string..'));
apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least three characters..'));

Visualforce Page
<apex:page controller="SOSLdemoExample">
<apex:form >
<apex:inputText value="{!searchStr}"/>
<apex:commandButton value="Search in Account, Contact, Opportunity" action="{!soslSearchmethod }" reRender="acct,error,oppt,cont" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start" >
<img src="/img/loading.gif"/>
<apex:outputPanel title="" id="error">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock title="Accounts" id="acct">
<apex:pageblockTable value="{!accList }" var="acc">
<apex:column value="{!}"/>
<apex:column value="{!acc.Type}"/>
<apex:pageBlock title="Contacts" id="cont">
<apex:pageblockTable value="{!conList}" var="con">
<apex:column value="{!}"/>
<apex:column value="{!}"/>
<apex:pageBlock title="Opportunities" id="oppt">
<apex:pageblockTable value="{!optyList}" var="opty">
<apex:column value="{!}"/>
<apex:column value="{!opty.StageName}"/>
5.New Features in SOQL:

a)“USING SCOPE” Query String:

We can implement the “USING SCOPE” clause for Returning Records that selected in scope. It offers Query filtering, that which offer you certain limit Result with Filter Scope.

b)Location Depended on SOQL Queries:

You can implement location and Distance variables, in binding the expressions that give you Reference Apex Variables in SOQL and SOSL queries that referred by a colon (:).

These are the best-known facts about SOQL, in upcoming blogs, we will update more data on this topic. Go through our blog Salesforce Future trends to get more updates on it.

Drop Us A Query

100% Secure Payments. All major credit & debit cards accepted.

Call Now Button