0% found this document useful (0 votes)
10 views6 pages

Collection Data Type

Uploaded by

SITHARTHAN V
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)
10 views6 pages

Collection Data Type

Uploaded by

SITHARTHAN V
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/ 6

Optmizing Salesforce Development

Collection Data Type


In Apex

By Rajat .C. Modi


By Rajat .C. Modi

𝐖𝐡𝐚𝐭 𝐢𝐬 collection data type


A collection data type is a way to group
multiple items together in programming. It
helps you manage and organize data more
easily. In Apex, there are three main types of
collections:
1. List
2. Set
3. Map
By Rajat .C. Modi

List
An ordered collection that can contain duplicates.
Use it when you need to maintain the order of
elements or allow duplicates.For example, storing a
list of contacts.

List<String> names = new List<String>();


names.add('Alice');
names.add('Bob');
By Rajat .C. Modi

Set
An unordered collection that does not allow
duplicates. Use it when you want to ensure
uniqueness of elements. For example, storing
unique IDs.

Set<String> uniqueIds = new Set<String>();


uniqueIds.add('001');
uniqueIds.add('002');
By Rajat .C. Modi

Map
A collection of key-value pairs, where each key is
unique. Use it when you need to associate unique
keys with specific values. For example, mapping
account IDs to account names.

Map<String, String> accountMap = new Map<String,


String>();
accountMap.put('001', 'Acme Corp');
accountMap.put('002', 'Globex Corp');
By Rajat .C. Modi

Summary

List: Ordered, allows duplicates.


Set: Unordered, no duplicates.
Map: Key-value pairs, unique keys.

Choose the appropriate type based on the


requirements of your application.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy