
Collections in Salesforce - A Brief Guide
Collections could be a sort of variable that can store numerous records. For case, List can store numerous Account object's records. Let us presently have a point-by-point diagram of all collection sorts.
List
A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. Lists can contain any collection and can be nested within one another and become multidimensional.
Example:
List<string> ListOfCities = new List<string>(); System.debug('Value Of ListOfCities'+ListOfCities);
Methods for Lists:
There are strategies accessible for Records that are ready to be utilized whereas programming to attain a few functionalities like calculating the estimate of List, including a component, etc. Following are a few most regularly utilized strategies −
- size()
- add()
- get()
- clear()
- set()
You'll be able to utilize the cluster documentation as well to pronounce the List, as given underneath, but usually not common hone in Pinnacle programming−
String [] ListOfStates = new List<string>();
Don't forget to check out: Why and How’s of Salesforce Training
Sets
A Set is a collection type that contains multiple numbers of unordered unique records. A Set cannot have duplicate records. Like Lists, Sets can be nested.
Example:
Set<string> ProductSet = new Set<string>{'Phenol', 'Benzene', 'H2SO4'}; System.debug('Value of ProductSet'+ProductSet);
Methods for Sets:
Set<string> ProductSet = new Set<string>{'Phenol', 'Benzene', 'H2SO4'}; ProductSet.add('HCL'); System.debug('Set with New Value '+ProductSet);
Check out another amazing blog by Marziya here: Learn About Salesforce Deployment Using Change Set
Maps
It may be a key esteem combine that contains a one-of-a-kind key for each esteem. Both key and esteem can be of any information sort.
Example:
Map<string, string> ProductCodeToProductName = new Map<string, string> {'1000'=>'HCL', '1001'=>'H2SO4'};
Responses