SOQL and SOSL Queries in Salesforce



SOQL:
1) It is Saleforce object Query Language(SOQL)
2) SOQL  retrieves the records from the database by using “SELECT” keyword.
3) By using SOQL, we can know in which objects or fields the data resides
4) We can retrieve records from only one Sobject. 

5) Return type of SOQL must be array/collection.
6) All fields API names are defined with comma separator.
7) Any SOQL query define with in square brackets ([]).


Syntax:
[select Field_API_Name from sobject]

Ex:
list<Account> listacc = new list<Account>();
listacc=[select Id, Name, Phone from Account];


SOSL:
1) It is Saleforce object Search Language(SOSL)
2) SOSL retrieves the records from the database by using “FIND” keyword.
3) By using SOSL, we don’t know in which objects or fields the data resides.
4) We can find text from more than one Sobject.

5) SOSL statements evaluate to a list of lists of SObjects where each list contains the search results for a particular SObject type.
6) SOSL queries are only supported in Apex classes and anonymous blocks.
7) We cannot use a SOSL query in a trigger.

Syntax:
list<list<SObject>> listsosl = [FIND ‘text’ IN ALL FIELDS RETURNING SObjects];
-More the one object, need to be define with comma separate.

Ex:
list<list<SObject>> listsosl = [FIND ‘IBM’ IN ALL FIELDS RETURNING Account, Contact, Employee__c];


  


Comments

Popular Posts