0

I need to pass List<WrapperClass> from lightning helper to apex class. Passing the list directly gave me the following error while iterating the list in apex.

Error message: An internal server error has occurred Error ID: 1137130244-1625 (119852647)

So I tried to stringify the list in helper and passed it as a string .This time I am getting the below error in apex.

QueryResult must start with '{'

Please find my code.

public class WrapperClass{
      @auraEnabled
      public Custom1__c custom1{get;set;}
      @auraenabled
      public Custom2__c custom2{get;set;}
      @auraenabled
      public List<Custom3__c> custom3List{get;set;}
      @auraenabled
      public List<String> currentList{get;set;}
}

Lightning helper:

       var action1 = component.get("c.saveCustomVolumes");
       {
       var customs = component.get("v.customIds");
       var tvList = component.get("v.wrapperList");
       var tvString = JSON.stringify(tvList);
       var baseYear = component.get("v.selectedYear");
       action1.setParams({
            "customList":customs,
            "tvString":tvString, // passing wrapper class as a String
            "baseYear":baseYear
        });
        action1.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {

                }

Apex class:

@auraenabled
public static saveCustomVolumes(List<String> customList,String tvString, String baseYear){
    List<WrapperClass> wrapList =          
 (List<WrapperClass>)JSON.deserialize(tvString,List<WrapperClass>.class); //This line gives the error QueryResult must start with '{'
}

Could anyone please help me with the issue.

8
  • You are getting internal server error in debug log or in Browser? Oct 12, 2018 at 6:07
  • can you please paste the string, which you are passing to the controller. Oct 12, 2018 at 6:17
  • I am getting Error message: An internal server error has occurred Error ID: 1137130244-2045 (-1373094418) in the browser
    – Sindhuja
    Oct 12, 2018 at 6:18
  • String passing to controller--> [{"currentEpisodes":["15.00","","","","","","","","","","",""],"Schedules":[{"Title__c":"a0O0j0000061rzXXXX","Id":"a0r0j0000002esXXXX","Date__c":"2018-01-01","Count__c":15,"Year__c":"2018","Month__c":1}],"title":{"Id":"a0O0j0000061rzXXXX","Name":"Test"},"updatedEpisodes":["100","200","30","40","50","60","70","80","90","100","110","120"]}]
    – Sindhuja
    Oct 12, 2018 at 6:26
  • Is the name of the JavaScript function calling the apex action same as the apex method name? If so, try renaming it.
    – Ranga
    Oct 12, 2018 at 6:31

2 Answers 2

1

I resolved this issue by forming JSON objects in javascript and adding it to a list and then passed this list to apex using JSON.stringify

1
  • Hi, Can you post the answer? Thanks.
    – sunny
    Jan 24, 2020 at 22:48
0

JSON String passed into apex method must match the wrapper class format. For example, JSON string should be something like,

[{
    "custom1" : {
        "Id" : "a0O0j0000061rzXXXX",
        "Name" : "Test"
    },
    "custom2" : {
        "Id" : "a0r0j0000002esXXXX",
        "Title__c" : "a0O0j0000061rzXXXX"
    },
    "custom3List" : [{
            "Id" : "a0r0j0000002esXXXX",
            "Title__c" : "a0O0j0000061rzXXXX"
        },{
            "Id" : "a0r0j0000002esXXXX",
            "Title__c" : "a0O0j0000061rzXXXX"
        }
    ],
    "currentList" : ["ABC","DEF"]
}]

You must log in to answer this question.

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