-
Notifications
You must be signed in to change notification settings - Fork 519
SOQLRecipes
Demonstrates how to make various types of SOQL calls including multi-object queries, and aggregate queries
Demonstrates how to use a bound variable in a WHERE clause
| Param | Description |
|---|---|
state |
String representing a US State code (AK, KS, etc.) |
System.debug(SOQLRecipes.getAccountsInState('ks'));Demonstrates how to use a complex WHERE clause in a SOQL query Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.getComplexFilteredList());Demonstrates how to query an object, as well as it's related child objects Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.getContactsAndAccounts());Demonstrates how to write a query that pulls information from two parent objects through a junction object Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.getDetailsFromBothParents());Demonstrates how to use a WHERE clause in a SOQL query Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.getFilteredList());Demonstrates how to use a bound variable to define the LIMIT
| Param | Description |
|---|---|
wantedNumberOfRows |
the number of rows desired |
System.debug(SOQLRecipes.getFirstXResults(5));Demonstrates how to query fields from a parent object through the relationship field Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.getParentDetailsForChild());Demonstrates how to get a limited number of results with a given offset; Ie: get the second set of 10 records. Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug('SOQLRecipes.getSecond10Accounts()');Demonstrates how to use the LIMIT clause in a SOQL statement Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.getSpecificNumberOfResults());demonstrates how to use aggregate methods, like Sum() or Count() in a SOQL query. This example generates the sum of opportunities associated with a specified Account Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
| Param | Description |
|---|---|
accountId |
an AccountId |
Id accountId = [SELECT id FROM Account LIMIT 1].Id;
System.debug(SOQLRecipes.getSumOfOpportunities(accountId));Demonstrates how to loop over a SOQL query Note: This method has a false-positive PMD warning. Our query includes the keyword 'WITH SECURITY_ENFORCED' which prevents this query from accessing fields and objects that they don't have permission to access. This is a form of inline CRUD/FLS Check.
System.debug(SOQLRecipes.queryMassiveNumberOfRecordsReturningCount());Demonstrates the proper way to query accounts with SOQL keeping FLS and CRUD in account. Note: This method has a false-positive PMD warning. PMD isn't aware of the purpose or functionality of CanTheUser.* so it doesn't undersatnd that we are, in fact, checking for CRUD / FLS permissions prior to querying.
List<Account> results = SOQLRecipes.querySingleObject();
System.debug(results);