-
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.) |
Type
List
Description
List
System.debug(SOQLRecipes.getAccountRecordsInState('ks'));Demonstrates how to write a query that pulls information from two parent objects through a junction object
Type
List<Junction__c>
Description
List<Junction__c>
System.debug(SOQLRecipes.getDetailsFromBothParentRecords());Demonstrates how to use a bound variable to define the LIMIT
| Param | Description |
|---|---|
wantedNumberOfRows |
the number of rows desired |
Type
List
Description
List
System.debug(SOQLRecipes.getFirstXRecords(5));Demonstrates how to loop over a SOQL query
Type
Integer
Description
integer
System.debug(SOQLRecipes.getLargeNumberOfRecords());Demonstrates how to query fields from a parent object through the relationship field
Type
List
Description
List
System.debug(SOQLRecipes.getParentRecordDetailsFromChildRecord());Demonstrates the proper way to query accounts with SOQL keeping FLS and CRUD in account.
Type
List
Description
list
List<Account> results = SOQLRecipes.querySingleObject();
System.debug(results);Demonstrates how to use a WHERE clause in a SOQL query
Type
List
Description
List
System.debug(SOQLRecipes.getRecordsByFieldValue());Demonstrates how to use a complex WHERE clause in a SOQL query
Type
List
Description
List
System.debug(SOQLRecipes.getRecordsByMultipleFieldValues());Demonstrates how to query an object, as well as it's related child objects
Type
List
Description
List
System.debug(SOQLRecipes.getRecordsWithRelatedRecords());Demonstrates how to get a limited number of results with a given offset; Ie: get the second set of 10 records.
Type
List
Description
List
System.debug('SOQLRecipes.getSecond10AccountRecords()');Demonstrates how to use the LIMIT clause in a SOQL statement
Type
List
Description
List
System.debug(SOQLRecipes.getSpecificNumberOfRecords());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
| Param | Description |
|---|---|
accountId |
an AccountId |
Type
Double
Description
Double
Id accountId = [SELECT id FROM Account LIMIT 1].Id;
System.debug(SOQLRecipes.getSumOfOpportunityRecords(accountId));