0% found this document useful (0 votes)
8 views11 pages

List Set Map - Collections in Apex (Salesforce)

The document explains collections in Salesforce, specifically focusing on Lists, Sets, and Maps. Lists are ordered collections that can contain duplicates, Sets are unordered and cannot contain duplicates, and Maps are key-value pairs where each key is unique. Each collection type requires initialization using the New keyword and has specific characteristics and use cases.

Uploaded by

Pallavi Namdev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

List Set Map - Collections in Apex (Salesforce)

The document explains collections in Salesforce, specifically focusing on Lists, Sets, and Maps. Lists are ordered collections that can contain duplicates, Sets are unordered and cannot contain duplicates, and Maps are key-value pairs where each key is unique. Each collection type requires initialization using the New keyword and has specific characteristics and use cases.

Uploaded by

Pallavi Namdev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

COLLECTIONS

Arrays in Salesforce world

Data type
holding more than one data
is called
Collection
LIST
Ordered Collection, Can contain Duplicate

List is a collection that can store elements


of any data type.
List has indexes
List can contains duplicate
List will automatically not change the
sequence of the data while handling
LIST
Example

List also requires initialisation using New keyword

examples:
List<String> myListString = New List<String> {'text1', 'text2', 'text3'};
List<Integer> myListInteger = New List<Integer> {1, 5, 7, 200, 21};
List<Account> accountList = new List<Account>();
SET
UnOrdered Collection, Cannot contain Duplicate

Set is an Unordered collection that can


store elements of any data type.
Set cannot hold duplicate
Set automatically rearranges the data in
increasing order
SET
UnOrdered Collection, Cannot contain Duplicate

Case Sensitive : Data inside the Set is case sensitive


so 'Banana' & 'banana' will be considered unique
No Indexing : it does not have index, means we
cannot access element by index
Because it auto index - we cannot add element at
specific index
In realtime Set is mostly useful for declaring IDs
SET
Example

Set also requires initialisation using New keyword

example:
Set<String> mySetString = New Set<String> {'Banana', 'Apple', 'Mango'};

System.debug(mySetString); //output : 'Apple', Banana', 'Mango';


MAP
Key Value Pair

Map is a key value pair where each unique


key map to a single value
Always declared as pair, never as single
Key has to be unique
Value can be duplicate
MAP
Key Value Pair

Map also requires initialisation using New Keyword

Syntax :
Map<IndexDataType, ValueDataType> mapName = New
Map<IndexDataType, ValueDataType> {1=>'element1', 2=>'element2'',
3=>'elem 3''};

Example 1: (IndexDataType = Integer and Value = String )


Map<Integer, String> mapFruits = New Map<Integer, String> {1=>'Apple',
2=>'Banana', 3=>'Mango'};
LIST METHODS
SET METHODS
MAP METHODS

You might also like