0

In my client side controller, I call a server side action that returns a List of custom objects. Each of those custom objects has multiple fields attached to it.

When printing the values in the backend (server side controller), this is the result I get :

allRecords = (Object_Name : [age=1,height=45,firstname=john,lastname=smith])

Now when the list is returned to my client side, I'm unable to retrieve the fields.

action.setCallback(this,function(result) {
  var r = result.getReturnValue();
  console.log('r = '+result);
});

Prints out [Object object]. I've tried using JSON.stringify and it prints out [{}]. Unsure of what I'm doing wrong. Thoughts?

3
  • Without seeing more code, all we can really do is guess. I'm guessing you didn't use @AuraEnabled on your wrapper class' attributes.
    – sfdcfox
    Aug 21 '18 at 23:19
  • 2
    Please do not use tags which have nothing to do with what you are asking. This question appears to have nothing to do with Salesforce Communities, so I have removed the [community] tag.
    – Adrian Larson
    Aug 21 '18 at 23:19
  • Looks like you want to print var r, instead you are printing result in your JS
    – Jayant Das
    Aug 22 '18 at 0:15
1

Assuming you have your aura controller written correctly and that you are also able to send request and get response from server, with the issue you have reported:

Now when the list is returned to my client side, I'm unable to retrieve the fields.

Unsure of what I'm doing wrong

Looking at what you have posted, you are printing result whereas you should be printing either the value of variable r or the return value from the result result.getReturnValue(), again assuming that you are returning the list from server.

Anything other than this will require seeing more code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.