SOQL for Admins | Get Started with SOQL Queries

preview_player
Показать описание
Optional SOQL Clauses
The SELECT clause and the FROM clause are required, but SOQL also has optional clauses to refine your query.

WHERE

The WHERE clause sets the conditions that a record must match to be selected and returned. Use the WHERE clause the same way you use filters to limit the data shown in a list view or report. For example, if we’re looking for a contact whose first name is Stella, we can add WHERE FirstName = 'Stella' to the end of our query, like this:
SELECT Name, Email FROM Contact WHERE FirstName = 'Stella'
You can also define the WHERE clause to filter using more than one condition. There are multiple ways to do this using three operators: AND, OR, and IN. Let’s consider some examples.

AND
Use AND to return records that meet two conditions. This query returns all records that have the first name Stella and the last name Pavlova.

SELECT Name, Email
FROM Contact
WHERE FirstName = 'Stella' AND LastName = 'Pavlova'

OR
Use OR to return records that meet one of two conditions. This query returns records with the last name James or the last name Barr.

SELECT Name, Email
FROM Contact
WHERE LastName = 'James' OR LastName = 'Barr'

IN
Use IN to return records that meet at least one of three or more conditions. The IN clause is commonly used to return the values of a picklist, or values from a LIST or SET. IN simplifies a query that would otherwise have many OR conditions. This query returns all records that have the last name James, Barr, Nedaerk, or Forbes.

SELECT Name, Email FROM Contact
WHERE LastName IN ('James', 'Barr', 'Nedaerk', 'Forbes')

LIMIT

The LIMIT keyword sets the maximum number of records to return. LIMIT is helpful when you’re testing and don’t want to wait for a query to process a large set of data. As you learn more about SOQL, you’ll discover more relevant ways to avoid returning too many records, but until then, LIMIT is an easy solution. Let’s try adding a limit to our query.

ORDER BY

Now that you have a handle on the quantity of results, how can you organize those results? Use the ORDER BY clause to sort results by the value of a specific field. Optionally, use a qualifier in an ORDER BY clause to specify ascending order (default) or descending order, just as you would in a spreadsheet. Finally, if you have many empty field values, use the NULLS qualifier to group all of the NULL values either first (default) or last.

Syntax
Description
Example
ASC
Returns results in ascending order
SELECT Name, Email FROM Contact
ORDER BY Name ASC
LIMIT 5

DESC
Returns results in descending order

SELECT Name, Email FROM Contact
ORDER BY Email DESC
LIMIT 5

NULLS
FIRST | LAST
Returns null records at the beginning (NULLS FIRST) or end (NULLS LAST)
SELECT Name, Email FROM Contact
ORDER BY Email
NULLS LAST

In the ASC example, SELECTName, Email FROM Contact ORDER BY Name ASC LIMIT 5 returns the Name and Email fields from five contacts, sorted in ascending order by name.

With this introduction to the power of SOQL, you can now retrieve huge sets of data, set limits to get very specific results, and organize returned data to suit your needs. Pretty sweet.

#salesforce #admin #trailhead #trending #begineer #coding #SOQL #trailheadworld @salesforce @SalesforceDevs @SalesforceAdmins @apexhours @trailheadworld @trailhead @TheCodingTrain
Рекомендации по теме
Комментарии
Автор

Please upload the Extended User and Restriction Superbadge unit sir please 🥺

crtgantaveerabhargavi