Posts

Showing posts with the label Collections

Salesforce Data collections List ,Set ,Map

In Salesforce Apex, data collections such as lists, sets, and maps are used to store and manipulate data. These collections offer different functionalities and are suited for different use cases. Here's an overview of each:  List : A list is an ordered collection of elements where each element has an index. Lists allow duplicate elements. Elements in a list can be accessed using their index. Lists are represented by the List class in Apex. Example : List<String> names = new List<String>(); names.add('Alice'); names.add('Bob'); names.add('Alice'); // Adding duplicate element System.debug(names); // Output: (Alice, Bob, Alice) Set : A set is an unordered collection of unique elements. It does not allow duplicate elements. Sets are useful when you need to ensure uniqueness and don't require the elements to be in a specific order. Sets are represented by the Set class in Apex. Example : Set<String> uniqueNames = new Set<String>(); uni...