Vahidkhan Lodi
What is the Difference between List, Set and Map in Salesforce?

List: A list is an ordered collection
so use list when you want to identify list element based on Index Number.(List can contain Duplicates)
EX: List accList = new List();

Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements.
So, use set if you want to make sure that your collection should not contain Duplicates.
EX: Set accSet = new Set()

Map: A map is a collection of key-value pairs where each unique key maps to a single value. Keys can be any primitive data type, while values can be a primitive, sObject, collection type or an Apex object.
EX: Map accMap = new Map();

By Vahidkhan Lodi in Salesforce on Jan 24 2023
  • Tuhin Paul
    Feb, 2023 22

    The key differences between List, Set, and Map in Salesforce are:

    1. List is an ordered collection of elements that can contain duplicates, Set is an unordered collection of unique elements, and Map is a collection of key-value pairs.
    2. List is accessed by index position, Set does not support index position and is accessed by the value itself, and Map is accessed by the key.
    3. List maintains order, Set does not maintain order, and Map does not guarantee order.
    4. List is useful when you need to maintain order and access elements by their index position, Set is useful when you need to perform operations on unique elements, and Map is useful when you need to access elements by a specific key.

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS