0

I have a apex class which is having one method with returntype wrapper class. i am binding the return type in helper in a response attribute (type is object). I want to fetch two variables i.e. id,status from response. Currently I am getting undefined error in output.

Reponse attribute in cmp:

<aura:attribute name="response" type="object"/>

Helper.js:

({ getStatusHelper : function(component, event,helper) {

    var jobID = event.getParam("Pass_Result");
    component.set("v.jobId", jobID);
    var action = component.get("c.getCalloutResponseStatus");
    
    action.setParams({"jobId": jobID});
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
           
           component.set("v.response", response.getReturnValue());
            **var getStatus = component.get("v.response").status; //GETTING UNDEFINED ERROR
            var getJobId = component.get("v.response").id; //GETTING UNDEFINED ERROR**
            
        }
        else{
            alert('Failed status call from child!!');
        }

});
      $A.enqueueAction(action);
}

})

can anyone pls help me on this issue.

2
  • It look Like problem problem in "id". JS is case-sensitive. try using "Id" var getJobId = component.get("v.response").Id; //GETTING UNDEFINED ERROR** Also, check other field also.
    – Sfdc_1184
    Jun 23, 2020 at 12:40
  • We would need to see your Apex code. This should only be a problem if you were returning a null value for some reason.
    – sfdcfox
    Jun 23, 2020 at 12:41

2 Answers 2

0

Make sure your wrapper class is public and has the @AuraEnabled notation in its variables, as well as they are public with get;set; example:

public class wrapperClass{
    @AuraEnabled public List<contact> lstContact{get;set;}
    @AuraEnabled public Integer contactCount{get;set;}
    @AuraEnabled public String headerMsg {get;set;}
}
1
  • Hi, All of them is already in place
    – Raj SF
    Jun 23, 2020 at 11:16
0

Try this:

if (component.isValid() && state === "SUCCESS") {
           const result = response.getReturnValue();
           component.set("v.response", result);
           let getStatus = result.status; //make sure it is not Status
           let getJobId = result.id; ////make sure it is not Id
}

You must log in to answer this question.

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