Soql and Sosl
Soql and Sosl
1. What is SOQL?
SOQL (Salesforce Object Query Language) is a query language used to search Salesforce data for
specific information. It is similar to SQL (Structured Query Language) but is designed specifically
for Salesforce’s object-oriented database. SOQL is used to retrieve records from Salesforce
objects and their related objects.
____________________________________________________________________________
Example:
NOT IN is used to filter records where a field does not match any value in the list.
Example:
______________________________________________________________________________
15. What is the purpose of SOSL and when would you use it?
SOSL is used to search across multiple objects in Salesforce for text or keyword-based searches.
It is especially useful when you want to search records based on user input, and you don’t know
which object contains the record. SOSL returns results from multiple objects (standard and
custom), such as Accounts, Contacts, Leads, etc.
You would use SOSL when:
You need to perform a broad search across multiple objects.
You need to search for records by keywords in text fields.
You are performing full-text searches across various fields and objects.
______________________________________________________________________________
EXAMPLES:
18. Query with Relationship (Parent-to-Child)
This query retrieves all Contacts related to a specific Account, including the Account Name.
FROM Account
The query selects the Account Name and the Contacts related to the Account.
FROM Contact
The query selects Contact details and includes Account details, specifically the Account Name.
FROM Opportunity
LIMIT 5
The query retrieves the most recent closed-won Opportunities sorted by the Close Date.
21. Query with Multiple Filters (AND/OR)
This query fetches Accounts in the 'Technology' or 'Healthcare' industry, with a revenue greater
than $10 million.
FROM Account
FROM Contact
FROM Opportunity
FROM Account
GROUP BY Name
The query aggregates the Amount from Opportunities related to each Account.
25. Query with LIKE and Wildcards
This query retrieves Accounts whose names contain the word "Global".
SELECT Name
FROM Account
FROM Contact
______________________________________________________________________________
FROM Opportunity
WITH SECURITY_ENFORCED