UTIL_List
Class · Group: Utilities
apex
global inherited sharing class UTIL_ListVarious list utilities for manipulating lists of objects and SObjects. This class provides methods for converting, transforming, sorting, and partitioning lists, as well as utility methods for checking emptiness and creating typed lists.
Example
apex
Boolean empty = UTIL_List.isEmpty(records);
List<List<SObject>> batches = UTIL_List.partition(records, 200);Methods
| Method | Description |
|---|---|
| global static Boolean isEmpty(List<Object> items) | Checks if an object array is empty or null. |
| global static Boolean isNotEmpty(List<Object> items) | Checks if an object array is not empty. |
| global static List<List<Object>> partition(List<Object> objects, Integer partitionSize) | Partitions a list into smaller lists of the specified size. |
isEmpty
apex
global static Boolean isEmpty(List<Object> items)Checks if an object array is empty or null.
Parameters
| Parameter | Type | Description |
|---|---|---|
items | List | The array to check. |
Returns Boolean — True if the array is null or empty, false otherwise.
Example
apex
List<Object> emptyList = new List<Object>();
Boolean isEmpty = UTIL_List.isEmpty(emptyList);
System.debug(isEmpty); // Outputs: trueisNotEmpty
apex
global static Boolean isNotEmpty(List<Object> items)Checks if an object array is not empty.
Parameters
| Parameter | Type | Description |
|---|---|---|
items | List | The array to check. |
Returns Boolean — True if the array is not null and not empty, false otherwise.
Example
apex
List<Object> numbers = new List<Object>{1, 2};
Boolean isNotEmpty = UTIL_List.isNotEmpty(numbers);
System.debug(isNotEmpty); // Outputs: truepartition
apex
global static List<List<Object>> partition(List<Object> objects, Integer partitionSize)Partitions a list into smaller lists of the specified size.
Parameters
| Parameter | Type | Description |
|---|---|---|
objects | List | A list of objects |
partitionSize | Object | The maximum size of each sub-list |
Returns Object — A list of sub-lists, each no larger than partitionSize
Example
apex
List<List<Object>> batches = UTIL_List.partition(records, 200);