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.

Since: 1.0

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 partition(List<Object> objects, Integer partitionSize)Partitions a list into smaller lists of the specified size.

Method Details

isEmpty

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

Checks if an object array is empty or null.

Parameters:

  • items (List) - The array to check.

Returns: Boolean - True if the array is null or empty, false otherwise.

Since: 1.0

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:

  • items (List) - The array to check.

Returns: Boolean - True if the array is not null and not empty, false otherwise.

Since: 1.0

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:

  • 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

Since: 1.0

Example:

apex
List<List<Object>> batches = UTIL_List.partition(records, 200);