What does Salesforce collection mean

What does Salesforce's Collection mean in 2023?

There are different kinds of collections in Salesforce that can hold a large number of records. Collections are thus sets of documents that belong to the same type. Depending on the demands of the business, collections might dynamically increase and decrease. Lists, sets, or maps can all be collections in Apex. The number of records that can be kept in a collection is unbounded. 

Since there was no software that could manage thousands of customers' records in one location, businesses previously had trouble keeping records for different clients. Salesforce collections made things better. By consolidating customer records in one location using Salesforce collections, businesses were able to increase customer satisfaction. 

Different Collections in Apex

There are three distinct collections in Salesforce:

  • Collection of list  
  • Set accumulation 
  • Collecting maps 

Lists Collection

One of the most significant types of collection is a list, which can contain any kind of data. A list is an ordered collection of any type of data, including user-defined types, primitive types, collections, sObjects, and built-in Apex types.

dont miss out iconDon't forget to check out: Learn All About Collections in Salesforce: List, Set and Map

The following are a list collection's main characteristics in Salesforce:

  • In a list collection, duplicates and null values are acceptable.
  • The keyword to declare a list collection is "List".
  • The initial entry in a list collection always has index position zero (0).
  • A collection of Apex lists has the capacity to expand dynamically over time.
  • The data type in a list collection might be either primitive or non-primitive.
  • The keyword must be used within the <> characters, followed by the data type to define a list collection.

The syntax for a list is as follows:

List<datatype> listName = new List<datatype>();

Set Collection

An unordered collection is a set. It is a singular collection of values without any duplications. Choose this collection if you don't want any duplicate items in your collection.

The following is a set collection's primary characteristics in Salesforce:

  • A set collection can contain any data type, including primitive data types and sObjects.
  • An index does not exist for a set collection.
  • There are never any duplicates or null values in a set collection.
  • In Salesforce Apex, set collections are not frequently used.
  • Collections that are nested inside of one another can be stored as sets.
  • To declare a set collection, you must use the set keyword and the name of the primitive data type enclosed in <> characters.

The syntax for a set is as follows:

Set<datatype> setName = new Set<datatype>();

dont miss out iconCheck out another amazing blog here: Implementing Data Collection for Impact Evaluations | Salesforce Guide

Maps Collection

A key-value combination called a "map" comprises the distinct key for each value. When anything must be rapidly located, it is used. 

The essential components of a map collection in Salesforce are as follows: 

  • In a map collection, the key and value can both be any type of data.  
  • The null value may be kept in a map key in a map collection. 
  • In a map collection, keys of the type string are case-sensitive. 
  • To declare a map collection, you must use the map keyword, followed by the key and value data types surrounded in <>. 

The syntax for a map is as follows:

Map<datatype_key,datatype_value> mapName = new Map<datatype_key,datatype_value>();


Popular Salesforce Blogs