Collections in APEX
Chapter Topics
- Apex Data Types
- Integer Data Type in APEX
- Floating Point Data Type in APEX
- String Data Type in APEX
- Date Datatypes in APEX
- Time and DateTime Data Types in APEX
- Boolean Datatype in Salesforce
- ID & Blob Datatypes in APEX
- What is the Rule of Conversions in Apex?
- Enums in APEX
- sObjects in Salesforce
- Generic sObjects in Salesforce
- Collections in APEX
- Lists in APEX
- List Array Notation in APEX
- Lists Initialization in APEX
- Nested Lists in APEX
- Sets in APEX
- Sets Initialization And Methods
- Maps in APEX
- Map Initialization Methods in APEX
- Operators in Apex and Their Types
- Shorthand Operator
- Equality Operator
- Relational Operators(<,>,<=,>=)
Apex language provides developers with three classes (Set, List, Map) that make it easier to handle the collection of objects. In a sense, these collections work somewhat like arrays except their size can change dynamically and they have more advanced behaviors and easier access methods than arrays.
Types of Collections in Apex
There are three main types of collections in Apex:
1. Lists
A list is an ordered group of items identified by their indices. List elements can be created using any data type, including primitive types, collections, sObjects, user-defined types, and integrated Apex types.
Lists are multidimensional and can contain any kind of collection. They can also be nested inside other lists. One may have, for instance, a list of lists of integer sets. A list can have up to eight layers total or up to seven levels of nested collections inside of it.
2. Sets
An unordered collection of unique elements without any duplicates is called a set. The element of Set could be any data type, including primitive types, collections, sObjects, user-defined types, and integrated Apex kinds.
Collections within sets have the ability to be nested inside one another. You may have a set of lists of lists of integer sets, for instance. A set can have up to eight levels total or up to seven levels of nested collections inside of it.
3. Maps
A map is an assembly of key-value pairings in which every distinct key corresponds to a single value. Any data type, including primitive types, collections, sObjects, user-defined types, and integrated Apex types, can be used for keys and values.
Map keys and values can contain any collection, including nested collections. One way to organize data is to create a map from integers to mappings, which then maps from strings to lists. Up to seven nested collection layers, or a maximum of eight levels total, may be present in map keys.
Next TopicNeed more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.