0

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?

5
  • See what a.getReturnValue() is holding in the setCallback before setting its value to opportunity. May be its not a valid. Commented Apr 19, 2017 at 13:15
  • What's quickest way to test for that just tried logging ton console but component doesn't run
    – Nebbyyy
    Commented Apr 19, 2017 at 13:21
  • Also your method(AddCNP, AddCP & AddECOM ) definitions are wrong. JS controller can not take list of specific type like apex. Remove them for once and try. Commented Apr 19, 2017 at 13:27
  • 1
    If you still need to see the response add console.log(JSON.stringify(a.getReturnValue())) and check the JavaScript console for what is output. You can check the request somewhat similarly by adding console.log(JSON.stringify(action.getParams())) before the request is enqueued. Also turn on server side logging to see if anything useful is reported there.
    – Keith C
    Commented Apr 19, 2017 at 13:54
  • Didn't quite understand "works not thanks so much", but I guess I helped, so I am glad. :) Commented Apr 19, 2017 at 14:10

1 Answer 1

1

Posting an answer just so the thread can be closed.

List<OpportunityLineItem> Oli = List<OpportunityLineItem>();

is not the appropiate way of declaring a list of type OpportunityLineItem in JavaScript.

Your Javascript code doesn't know what is OpportunityLineItem, so for JS, its just an array to which you can put any one kind of items.

So declare an array like this:

var Oli = [];

then push items into it:

Oli.push(oliItem);

You must log in to answer this question.

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