I am having an issue adding my lightning component onto my opportunity page for testing the error is
Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. Unable to parse JSON response
my component is basic consisting of my .cmp, .js and my controller listed below:
.cmp
<aura:component controller ="AddProductsController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
<aura:attribute name="opportunity" type="Opportunity"/>
<aura:attribute name="oppId" type="String" default="{!v.recordId}"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<ui:button label="Card Not Present" press="{!c.AddCNP}"/>
<li></li>
<ui:button label="Card Present" press="{!c.AddCP}"/>
<li></li>
<ui:button label="Eccomerce" press="{!c.AddECOM}"/>
<h1>{!v.oppId}</h1>
</aura:component>
.js
({
doInit : function(component, event, helper) {
var action = component.get("c.getOpp");
action.setParams({
"oppId": component.get("v.recordId")
});
action.setCallback(this, function(a) {
var state = a.getState();
if (state === "SUCCESS") {
component.set("v.opportunity", a.getReturnValue());
}
else{
console.log('Error init function' + state);
}
});
$A.enqueueAction(action);
},
AddCNP : function(component, event, helper) {
List<OpportunityLineItem> Oli = List<OpportunityLineItem>();
},
AddCP : function(component, event, helper) {
List<OpportunityLineItem> Oli = List<OpportunityLineItem>();
},
AddECOM : function(component, event, helper) {
List<OpportunityLineItem> Oli = List<OpportunityLineItem>();
}
})
Controller
public with sharing class AddProductsController {
@AuraEnabled
public static Opportunity getOpp(Id oppId){
return([Select id, Name
From Opportunity Where id=:oppId]);
}
}
As far as I am aware I have implemented it correctly and the opportunity object just be being parsed onto the view. Any ideas?
a.getReturnValue()
is holding in the setCallback before setting its value to opportunity. May be its not a valid.console.log(JSON.stringify(a.getReturnValue()))
and check the JavaScript console for what is output. You can check the request somewhat similarly by addingconsole.log(JSON.stringify(action.getParams()))
before the request is enqueued. Also turn on server side logging to see if anything useful is reported there.