I am trying to fetch Map in my lightning js controller.
Apex Controller:
@AuraEnabled
public static Map<CustomObject__c, custObj__c> getQuestions(){
Map<CustomObject__c,custObj__c> quesOpMap = new Map<CustomObject__c, custObj__c>();
List<custObj__c> obj = [SELECT Id,Name FROM custObj__c];
for(CustomObject__c q : [SELECT Id,Name FROM CustomObject__c] )
{
for(custObj__c opt : obj){
quesOpMap.put(q, opt);
}
}
return quesOpMap;
}
JS Controller:
var action = component.get("c.getQuestions");
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.questions", response.getReturnValue());
}
else {
console.log("Failed with states: " + state);
}
on loading app I am getting error as 'Unable to parse JSON Response' and if check console log for response.getReturnValue()
. this is undefined.
But If I replace Map<CustomObject__c, custObj__c>
with any primitive type for e.g. - Map<Id,String> or Map<String,String>
, js controller is working fine.
How to get values for custom objects in lightning controller?