May 2019
Intermediate to advanced
546 pages
12h 41m
English
A collection can be a collection of Set, List, or Map instances. The for loop is used to iterate the code in a structure when looping a collection of records.
When looping through a map with records, you always need to define which of the two values you want to iterate. Here is an example:
Map<Integer, String> mapNumbers = new Map<Integer, String>{ 1 => 'One', 2 => 'Two', 3 => 'Three'};// Iteration over the indexes of the mapFor (Integer iNumber : mapNumbers.keySet()){ // the keyset()-function of a map returns a set of the keys from the map. This is always a set of objects, defined in the map. In this case 1, 2 and 3 ...}// iteration over the values of the mapFor (String sString : mapNumbers.values()){ // the values()-function ...Read now
Unlock full access