+ Start a Discussion
wsmithwsmith 

Do enum data types have a base type?

I want to create a method that handles null enum values.  Do I have to create a handler method for each enum data type I want to check or is there a base enum type that enums derive from which the "instanceof" operator will work?

 

i.e.

enum A {ONE, TWO}

enum B {THREE, FOUR}

 

void checkEnum(<DataType> value) {

    if (value == null)

    // log error, etc.

}

 

However, A and B are not an "instanceof" Object nor sObject so what can "<DataType>" be?

sfdcfoxsfdcfox

I was looking for another solution, and I came across this unanswered thread, so for future reference:

 

In the example code, A and B are the data types. That is to say:

 

void checkenum(object value) {
  if(value instanceof a) {
    System.debug('This is an A enum value');
  }
  if(value instanceof b) {
    System.debug('This is a B enum value');
  }
}

...

checkenum(a.two);
checkenum(b.three);

...

USER_DEBUG:This is an A enum value
...
USER_DEBUG:This is a B enum value