Pass an enum value from lightning controller to Apex
up vote
3
down vote
favorite
Is it possible to pass an enum value from lightning controller to Apex?
Here is what I tried
lightning component part
const action = component.get("methodC");
action.setParams({p: "VIEW"});
action.setCallback(component, function(){});
$A.getCallback(function(){$A.enqueueAction(action);})();
apex part
public enum Mode { CREATE, VIEW, EDIT }
@AuraEnabled
public static void methodC(Mode p) {
System.debug('p:' + p);
}
And here is the error I am getting:
16:35:58:002 FATAL_ERROR System.JSONException: Illegal value for primitive
Would be grateful for any relevant documentation on the topic. Here is what I was able to find, but it is of no use for my question about lightning client-side and Apex enum.
Thank you.
apex lightning parameters enum
add a comment |
up vote
3
down vote
favorite
Is it possible to pass an enum value from lightning controller to Apex?
Here is what I tried
lightning component part
const action = component.get("methodC");
action.setParams({p: "VIEW"});
action.setCallback(component, function(){});
$A.getCallback(function(){$A.enqueueAction(action);})();
apex part
public enum Mode { CREATE, VIEW, EDIT }
@AuraEnabled
public static void methodC(Mode p) {
System.debug('p:' + p);
}
And here is the error I am getting:
16:35:58:002 FATAL_ERROR System.JSONException: Illegal value for primitive
Would be grateful for any relevant documentation on the topic. Here is what I was able to find, but it is of no use for my question about lightning client-side and Apex enum.
Thank you.
apex lightning parameters enum
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Is it possible to pass an enum value from lightning controller to Apex?
Here is what I tried
lightning component part
const action = component.get("methodC");
action.setParams({p: "VIEW"});
action.setCallback(component, function(){});
$A.getCallback(function(){$A.enqueueAction(action);})();
apex part
public enum Mode { CREATE, VIEW, EDIT }
@AuraEnabled
public static void methodC(Mode p) {
System.debug('p:' + p);
}
And here is the error I am getting:
16:35:58:002 FATAL_ERROR System.JSONException: Illegal value for primitive
Would be grateful for any relevant documentation on the topic. Here is what I was able to find, but it is of no use for my question about lightning client-side and Apex enum.
Thank you.
apex lightning parameters enum
Is it possible to pass an enum value from lightning controller to Apex?
Here is what I tried
lightning component part
const action = component.get("methodC");
action.setParams({p: "VIEW"});
action.setCallback(component, function(){});
$A.getCallback(function(){$A.enqueueAction(action);})();
apex part
public enum Mode { CREATE, VIEW, EDIT }
@AuraEnabled
public static void methodC(Mode p) {
System.debug('p:' + p);
}
And here is the error I am getting:
16:35:58:002 FATAL_ERROR System.JSONException: Illegal value for primitive
Would be grateful for any relevant documentation on the topic. Here is what I was able to find, but it is of no use for my question about lightning client-side and Apex enum.
Thank you.
apex lightning parameters enum
apex lightning parameters enum
asked 2 days ago
oobarbazanoo
18710
18710
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
The types that can be passed are limited, leaving you to have to do more work than ideal sometimes.
In this case, code like this should work:
@AuraEnabled
public static void methodC(String p) {
Mode pMode = toMode(p);
...
}
private static Mode toMode(String s) {
for (Mode m : Mode.values()) {
if (m.name() == s) return m;
}
return null;
}
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
The types that can be passed are limited, leaving you to have to do more work than ideal sometimes.
In this case, code like this should work:
@AuraEnabled
public static void methodC(String p) {
Mode pMode = toMode(p);
...
}
private static Mode toMode(String s) {
for (Mode m : Mode.values()) {
if (m.name() == s) return m;
}
return null;
}
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
add a comment |
up vote
6
down vote
accepted
The types that can be passed are limited, leaving you to have to do more work than ideal sometimes.
In this case, code like this should work:
@AuraEnabled
public static void methodC(String p) {
Mode pMode = toMode(p);
...
}
private static Mode toMode(String s) {
for (Mode m : Mode.values()) {
if (m.name() == s) return m;
}
return null;
}
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
add a comment |
up vote
6
down vote
accepted
up vote
6
down vote
accepted
The types that can be passed are limited, leaving you to have to do more work than ideal sometimes.
In this case, code like this should work:
@AuraEnabled
public static void methodC(String p) {
Mode pMode = toMode(p);
...
}
private static Mode toMode(String s) {
for (Mode m : Mode.values()) {
if (m.name() == s) return m;
}
return null;
}
The types that can be passed are limited, leaving you to have to do more work than ideal sometimes.
In this case, code like this should work:
@AuraEnabled
public static void methodC(String p) {
Mode pMode = toMode(p);
...
}
private static Mode toMode(String s) {
for (Mode m : Mode.values()) {
if (m.name() == s) return m;
}
return null;
}
answered 2 days ago
Keith C
93.7k1088199
93.7k1088199
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
add a comment |
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
if you try returning enum value back from Apex to lightning controller it returns blank object as well.
– Pranay Jaiswal
2 days ago
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f241905%2fpass-an-enum-value-from-lightning-controller-to-apex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown