top of page

Apex Enums in Salesforce

Sep 19, 2021
1 min read

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')





2 Comments


Hindi world
Hindi world
4 days ago

Before dealing with any property matter, checking the available records is always a sensible step. The MP Bhulekh Portal makes it easier for citizens to access land-related information online whenever required.

Like

I appreciate the convenience of MPTAAS Login for students. Online account access means users can manage important scholarship-related information from home. Clear login instructions are especially useful for first-time portal users.

Like
bottom of page