UTIL_Map
Class · Group: Utilities
global inherited sharing class UTIL_MapStatic helper methods for common Map operations in Apex, including key-value transformation, entry joining, equality comparison, SObject indexing, and case-insensitive lookups.
Example
Map<String, String> params = new Map<String, String>{'key' => 'value', 'name' => 'test'};
String delimited = UTIL_Map.toDelimitedString(params, ',');Methods
| Method | Description |
|---|---|
| global static List<SObject> flattenValues(Map<Id, List<SObject>> idMap) | Collapses an Id-keyed map of SObject lists into a single flat list containing every record. |
| global static List<SObject> flattenValues(Map<String, List<SObject>> stringMap) | Collapses a String-keyed map of SObject lists into a single flat list containing every record. |
| global static String toDelimitedString(Map<String, String> valuesByNameMap, String separator) | Serialises a map of name-value pairs into a single delimited string of the form name=value[separator]name=value. |
flattenValues
global static List<SObject> flattenValues(Map<Id, List<SObject>> idMap)Collapses an Id-keyed map of SObject lists into a single flat list containing every record.
Parameters
| Parameter | Type | Description |
|---|---|---|
idMap | Map | A map where the value is a list of SObjects and the key is an Id |
Returns SObject — A list containing all the SObjects from the map
Example
Map<Id, List<SObject>> contactsByAccount = new Map<Id, List<SObject>>();
List<SObject> allContacts = UTIL_Map.flattenValues(contactsByAccount);global static List<SObject> flattenValues(Map<String, List<SObject>> stringMap)Collapses a String-keyed map of SObject lists into a single flat list containing every record.
Parameters
| Parameter | Type | Description |
|---|---|---|
stringMap | Map | A map where the value is a list of SObjects and the key is a string |
Returns SObject — A list containing all the SObjects from the map
Example
Map<String, List<SObject>> recordsByType = new Map<String, List<SObject>>();
List<SObject> allRecords = UTIL_Map.flattenValues(recordsByType);toDelimitedString
global static String toDelimitedString(Map<String, String> valuesByNameMap, String separator)Serialises a map of name-value pairs into a single delimited string of the form name=value[separator]name=value.
Parameters
| Parameter | Type | Description |
|---|---|---|
valuesByNameMap | Map | A map of name and values |
separator | String | The separator to use between pairs; defaults to comma if null |
Returns String — A string in the format paramName=paramValue[separator]paramName2=paramValue2
Example
Map<String, String> params = new Map<String, String>{ 'key1' => 'value1', 'key2' => 'value2' };
String result = UTIL_Map.toDelimitedString(params, ',');Inner Classes
| Class | Description |
|---|---|
| CaseInsensitiveMap | A Map implementation that performs case-insensitive key lookups. |