0

I am trying to return multiple values from the apex to javascript using wire decorator. Because of functions in apex cannot return multiple values at the same time, I am returning custom class wrapper which has instance variables mapped to values I want to return.

I tested the apex code using the developer console, it's working fine. Problem is at the javascript side, instead of getting the custom class wrapper instance, I am getting empty object {}.

Type of values I am trying to return can be Standard Objects or Custom Objects.

Thank you.

1
  • 1
    It'd help if you would include the relevant bits of code that you've written so far (both the Javascript and the Apex). Doing that helps show that you've made a good-faith effort to resolve your problem on your own. It's also somewhere between hard and impossible to debug code issues without seeing the code. You can edit your question to add these details.
    – Derek F
    Commented Aug 10, 2019 at 12:26

1 Answer 1

6

The attributes in the custom class that you have created should have the AuraEnabled annotation set on them. Then those attributes will be accessible on the javascript side.

public class MultiValueReturn {
    @AuraEnabled
    public Decimal val1;
    @AuraEnabled
    public String val2;
}
2
  • That worked. I thought we can have AuraEnabled annotation for only static values and methods. Thank you.
    – Sri Harsha
    Commented Aug 12, 2019 at 4:37
  • Lifesaver! Such a small annotation, such a big difference. Where did you find this? Commented Apr 30, 2020 at 13:24

Not the answer you're looking for? Browse other questions tagged .