Skip to content

UTIL_List

Class · Group: Utilities

apex
global inherited sharing class UTIL_List

Various 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

MethodDescription
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

ParameterTypeDescription
itemsListThe 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: true

isNotEmpty

apex
global static Boolean isNotEmpty(List<Object> items)

Checks if an object array is not empty.

Parameters

ParameterTypeDescription
itemsListThe 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: true

partition

apex
global static List<List<Object>> partition(List<Object> objects, Integer partitionSize)

Partitions a list into smaller lists of the specified size.

Parameters

ParameterTypeDescription
objectsListA list of objects
partitionSizeObjectThe 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);