Welcome to my blog

I have been working with Salesforce for quite a while, so don’t hesitate to contact me if you have any questions or want some advice.

s f

Subscribe
Follow Us
h

APEX COLLECTIONS IN SALESFORCE

 . Apex  . APEX COLLECTIONS IN SALESFORCE

APEX COLLECTIONS IN SALESFORCE

Simple Explanation About Apex Collections & Its Types in Salesforce

Simple explanation about collections and its types in Apex:

Collections in Apex:

A collection is a type of variable that can store multiple number of records or items. Collections are work like arrays and they have more advanced behaviors and easier access methods than arrays. Data collections are groupings of any data types for example List can collect multiple number of sObjects records.

Types of collection:

  • List
  • Set
  • Map

List:

List is an ordered group of items of the same data type that are distinguished by their indices.  List elements can be of any data type like primitive types, collections, sObjects, user-defined types and built-in Apex types . Example for list is collection of Account records in Account object . Also List can contain duplicate values for example same Account repeated multiple times and lists are the mostly used collection in salesforce.

Syntax for List in String data type==>

1
 List<String> myList=new List<String>();

Set:

Set is collection of unique, unordered elements of the same data type and set elements can be of any data type of primitive types, collections, sObjects, user-defined types and built-in Apex types. A set maintains no particular order for its elements. Because the elements are unordered, Also a set can’t have any duplicate values.

Syntax for Set String data type==>

1
 Set<String> myList=new Set<String>();

Map:

Map is a collection of key-value pairs where each unique key maps to a single value. Also map is more complex collection than either List or Set. Map has the two major parts and they are key and value , called Key-Value pair. Keys and values can be any data type of primitive types, collections, sObjects, user-defined types, and built-in Apex types.

Syntax for Map String data type==>

1
 Map<String(key), String(value)> myMap= new Map<String, String>();

Comments

Post a Comment