Switch: Enum value used in 'when expression' should be unqualified
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Background
I am getting this error message three times:
Enum value used in 'when expression' should be unqualified
In relation to this code:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when Schema.DisplayType.STRING // this line errors
// do stuff
when Schema.DisplayType.CURRENCY // this line errors
// do stuff
when Schema.DisplayType.DOUBLE // this line errors
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
Questions
- Why am I getting the error?
- How do I fix it?
apex enum switch-case
add a comment |Â
up vote
1
down vote
favorite
Background
I am getting this error message three times:
Enum value used in 'when expression' should be unqualified
In relation to this code:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when Schema.DisplayType.STRING // this line errors
// do stuff
when Schema.DisplayType.CURRENCY // this line errors
// do stuff
when Schema.DisplayType.DOUBLE // this line errors
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
Questions
- Why am I getting the error?
- How do I fix it?
apex enum switch-case
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Background
I am getting this error message three times:
Enum value used in 'when expression' should be unqualified
In relation to this code:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when Schema.DisplayType.STRING // this line errors
// do stuff
when Schema.DisplayType.CURRENCY // this line errors
// do stuff
when Schema.DisplayType.DOUBLE // this line errors
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
Questions
- Why am I getting the error?
- How do I fix it?
apex enum switch-case
Background
I am getting this error message three times:
Enum value used in 'when expression' should be unqualified
In relation to this code:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when Schema.DisplayType.STRING // this line errors
// do stuff
when Schema.DisplayType.CURRENCY // this line errors
// do stuff
when Schema.DisplayType.DOUBLE // this line errors
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
Questions
- Why am I getting the error?
- How do I fix it?
apex enum switch-case
apex enum switch-case
asked 1 hour ago
Robs
1,141423
1,141423
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when STRING
// do stuff
when CURRENCY
// do stuff
when DOUBLE
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when STRING
// do stuff
when CURRENCY
// do stuff
when DOUBLE
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
add a comment |Â
up vote
3
down vote
accepted
You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when STRING
// do stuff
when CURRENCY
// do stuff
when DOUBLE
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when STRING
// do stuff
when CURRENCY
// do stuff
when DOUBLE
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:
Schema.DisplayType fieldType = getType(fieldName);
switch on fieldType
when STRING
// do stuff
when CURRENCY
// do stuff
when DOUBLE
// do stuff
when else
throw new CustomException('Unknown field type: ' + fieldType);
answered 43 mins ago


Aidan
5,903937
5,903937
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f234174%2fswitch-enum-value-used-in-when-expression-should-be-unqualified%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password