1

I have created an array of list custom setting in JS controller of lightning component. When I call apex controller method and pass this array, inside controller its value comes as empty. However, when I pass a single record of the same custom setting, that value is accessed successfully and I can see all its field values.

I think that there is some way that I am unknown in Javascript where you can send an array of list custom setting to apex. Does anybody has idea about this?

My code of lightning component helper:

//"setting" is the list custom setting record passed as attribute in an event
//"updatedCustomSettingList" is the attribute in this component of type "list" used to  fill everytime a record is sent to this component
createSettingList : function(component, event){
    var setting=event.getParam("setting");
    var updatedCustomSettingList = [];
    updatedCustomSettingList=component.get("v.updatedCustomSettingList");
    updatedCustomSettingList.push({
        value : setting
    });
    component.set("v.updatedCustomSettingList", updatedCustomSettingList);
}

Component:

<aura:attribute name="updatedCustomSettingList" type="list" />

Apex controller method:

 public static void updateEditedValues(List<TimeTrackerConfigSettings__c> settingList){
    system.debug('inside method, setting returned is: '+ settingList); //value comes as {}

2 Answers 2

3

I've found the best way to get around this sort of issue is to serialize your setting list in the Javascript controller and deserialize in your Apex Controller.

Something like this:

action.setParams({
  "jsonParams": JSON.stringify(yourArray)
});
action.setCallback(this, function(response) {.... etc

In the controller, make sure you change the param type to string and deserialize like so:

@AuraEnabled
public static String saveData(String jsonParams) {

    List<TimeTrackerConfigSettings__c> settings;
    try {
        settings = (List<TimeTrackerConfigSettings__c>)JSON.deserialize(jsonParams, List<TimeTrackerConfigSettings__c>.class);
    } catch (Exception e) {
        //handle error
    }

    //process settings as per normal
3
  • Perfect...I was trying exactly the same and was able to get the serialised string in apex just before I read your answer :) BUT...... new problem here: Getting exception: FATAL_ERROR System.JSONException: Json Deserialization failed on token 'null' and has left off in the middle of parsing a row. Will go to end of row to begin parsing the next row.
    – Sarang
    Nov 21, 2016 at 6:38
  • DONE!! there was a problem in my generated JSON string. Finally got the required thing :)
    – Sarang
    Nov 21, 2016 at 7:10
  • Hah, I was just going to say that that's what you should check before sending to the Apex controller. Glad you got it :) Nov 21, 2016 at 7:34
0

without stringyfy also you can pass any collection

action.setParams({
        insertSobjRecordMap:fieldValueBindingMap

        });

      public static void createContactOpportunityRecord(Map<String,String>  insertSobjRecordMap){

        System.debug('insertSobjRecord>>'+insertSobjRecordMap);


      }

You must log in to answer this question.

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