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);
},
5

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

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

and then deserialising in the controller

|improve this answer|||||
  • 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 '17 at 16:14
  • Thanks! This helped me as well. I had same issue then used the JSON.sringify and it worked. – dphil May 17 '17 at 15:04
  • This helped me a lot, thx. – Christian Szandor Knapp Mar 27 '18 at 14:40

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.