top of page
Search

Apex Enums in Salesforce

An enum is an abstract data type with values that each take on exactly one of a finite set of identifiers that you specify. Enums are typically used to define a set of possible values that don’t otherwise have a numerical order. Typical examples include the suit of a card, or a particular season of the year.


Although each value corresponds to a distinct integer value, the enum hides this implementation. Hiding the implementation prevents any possible misuse of the values to perform arithmetic and so on. After you create an enum, variables, method arguments, and return types can be declared of that type.



public enum RecordType {Customer , Person , Internal}

From the above code statement says RecordType have 3 values. If apex code is checking for any condition , no need to hardcode values anywhere and we can restrict the apex code not to have any other declaration with enum RecordType.

How to assign value to enum

​Type

Code Syntax

​Using enum as a Data Type

​RecordType rt = RecordType.Person;

​Passing String as a Value

​RecordType rt = RecordType.valueOf('Person')





160 views0 comments
bottom of page