4

I've looked through the various questions here on this topic but still can't find the solution.

I'm trying to upsert a list of records, but keep getting the above error. Code snippets below, any suggestions appreciated.

<div class="slds-p-around--small slds-align--absolute-center">
    <lightning:button variant="brand" label="Save" onclick="{!c.createTimesheet}" />
</div>

controller

createTimesheet : function(component, event, helper){
    var newTimesheet = component.get("v.timesheets");
    helper.createTimesheet(component, newTimesheet);
},

helper

    createTimesheet : function(component, timesheets){
    this.upsertTimesheets(component, timesheets, function(response){
        var state = response.getState();
        if (state === "ERROR") {
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " + 
                             errors[0].message);
                }
            } else {
                console.log("Unknown error");
            }
        }
        timesheets.push(response.getReturnValue());
        component.set("v.timesheets", timesheets);
    });
},

upsertTimesheets : function(component, timesheets, callback){
    var action = component.get("c.saveTimesheets");
    timesheets.sobjectType = 'Timesheet_Unit__c';
    action.setParams({"timesheets": timesheets});
    if(callback){
        action.setCallback(this, callback);
    }
    $A.enqueueAction(action);
},
2

1 Answer 1

5

Managed to get this working using JSON.stringify e.g.

action.setParams({"timesheets": JSON.stringify(timesheets)});

and then deserialising in the controller

3
  • Glad you got it working. I am looking forward to when they fix this and the issue with empty variables in classes sent to client. I can then clean up my code a lot
    – Eric
    May 5, 2017 at 16:14
  • Thanks! This helped me as well. I had same issue then used the JSON.sringify and it worked.
    – dphil
    May 17, 2017 at 15:04
  • This helped me a lot, thx. Mar 27, 2018 at 14:40

You must log in to answer this question.

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