SOQL OVERVIEW
COMMON KEYWORDS
SELECT AND
Select records from your Salesforce Org Filter conditions that all must be true
OR
FROM Filter conditions that only one must be true
Identify the Salesforce object from which
LIMIT
we are retrieving records
Specify the maximum number of records returned
ORDER BY
WHERE
Specify the order of the records being returned
Filter records that meet specific conditions
SOQL EXAMPLES SOQL IN APEX
Retrieve all accounts with the id, name, and Retrieve accounts and store the values in a
website fields: list
List<Account> accounts = [SELECT Id, Name,
SELECT Id, Name, Website FROM Account
Website FROM Account];
Retrieve only Cases where the status is Closed Retrieve a single opportunity and store it in a
variable
SELECT Id FROM Case WHERE Status = 'Closed' Opportunity opp = [SELECT Id, Name,
Amount FROM Opportunity LIMIT 1];
Relationship Queries
Retrieve a single field value and store it in a
Child to Parent variable
Retrieve all contacts with account name
String clientEmail = [SELECT Id, Email FROM
SELECT Id, Name, Account.Name FROM Contact Contact LIMIT 1].Email;
Retrieve all cases and iterate over each
Parent to Child
Retrieve all child contacts with the name and record
email for each account for (Case ca : [SELECT Id, Status FROM Case]) {
System.debug('Case Status: ' + ca.Status);
SELECT Id, Name,
}
(SELECT FirstName, Email FROM Contacts)
FROM Account
www.salesforcementor.com