Newer Version Available

This content describes an older version of this product. View Latest

Enum Methods

An enum is an abstract data type with values that each take on exactly one of a finite set of identifiers that you specify. Apex provides built-in enums, such as LoggingLevel, and you can define your own enum.

All Apex enums, whether user-defined enums or built-in enums, have the following common method that takes no arguments.

values
This method returns the values of the Enum as a list of the same Enum type.

Each Enum value has the following methods that take no arguments.

name
Returns the name of the Enum item as a String.
ordinal
Returns the position of the item, as an Integer, in the list of Enum values starting with zero.

Enum values cannot have user-defined methods added to them.

For more information about Enum, see Enums.

Example

1Integer i = StatusCode.DELETE_FAILED.ordinal();
2
3String s = StatusCode.DELETE_FAILED.name();
4
5List<StatusCode> values = StatusCode.values();