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?

  • See what a.getReturnValue() is holding in the setCallback before setting its value to opportunity. May be its not a valid. – Santanu Halder Apr 19 '17 at 13:15
  • What's quickest way to test for that just tried logging ton console but component doesn't run – Nebbyyy Apr 19 '17 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. – Santanu Halder Apr 19 '17 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 Apr 19 '17 at 13:54
  • Didn't quite understand "works not thanks so much", but I guess I helped, so I am glad. :) – Santanu Halder Apr 19 '17 at 14:10
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);
| improve this answer | |

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.