0

I am temporarily storing changes to records in a Map by Id in my Lightning component

Markup:

<aura:component controller="MyController">
     <aura:attribute name="changes" type="Map" default="{}" access="private" /> 
     ...
</aura:component>

JS Controller Code:

var changes = cmp.get("v.changes");
changes[recordId] = {
   sobjectType: 'NAMESPACE__MyCustomRecord__c',
   Id: recordId,
   ...
};
cmp.set("v.changes", changes);

var action = cmp.get("c.save");  
action.setParams({
        changes: cmp.get("v.changes")
    });

Apex Controller:

@AuraEnabled
public static void save(Map<Id, SObject> changes) {
    update changes.values();
}

When I invoke this the Apex save() method throws an

An internal server error has occurred Error ID: 1757078119-115612 (1843984413) Error

5

1 Answer 1

2

I just had to change my Apex method to not work on generic SObject but a concrete type Account.

@AuraEnabled
public static void save(Map<Id, Account> changes) {
    update changes.values();
}

After that everything worked.

1
  • 2
    Whenever I run into that I just JSON.stringify and deserialize in the apex method
    – Eric
    Commented Nov 24, 2017 at 16:27

You must log in to answer this question.

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