Skip to content

IterationRecipes

pozil edited this page Nov 14, 2024 · 12 revisions

IterationRecipes Class

Demonstrates how to iterate on lists and sets

Group Collection Recipes

See IterableApiClient

Methods

iterateOnAccountList(accounts)

Demonstrates how to iterate on a list of SObject thanks to the Iterable and Iterator interfaces. This example iterates on Accounts to sum the 'number of employees' field values (use the SUM SOQL function for a real-life application).

Signature

public static Integer iterateOnAccountList(List<Account> accounts)

Parameters

Name Type Description
accounts List<Account> a list of accounts that will be iterated on

Return Type

Integer

Total number of employees for the accounts


iterableApiClientRecipe()

Demonstrates how to use a REST API client that leverages the Iterator interface. This example iterates on a paginated record list. Records are represented as strings for simplicity. Remote records are retrieved on the fly by IterableApiClient when the Iterator is accessed.

Signature

public static List<String> iterableApiClientRecipe()

Return Type

List<String>

List of "records" retrieved

Clone this wiki locally