0

With lightning , I need to be able to transfer obects related list data from server to client then to client to server.

From server to client, it works correctly , the content of related list is well retrieved.

AccountFromServer: {
  "Name": "SomeAccount",
  "Id": "0013600000kJhmDAAS",
  "Contacts": [
    {
      "AccountId": "0013600000kJhmDAAS",
      "Id": "0033600000Xy9DyAAJ",
      "Name": "Contact1"
    },
    {
      "AccountId": "0013600000kJhmDAAS",
      "Id": "0033600000Xy9EDAAZ",
      "Name": "Contact2"
    },
    {
      "AccountId": "0013600000kJhmDAAS",
      "Id": "0033600000Xy9ESAAZ",
      "Name": "Contact3"
    }
  ]
}

But when i send the same data to the server again, the related list content is deleted.

AccountAfterServerTransfer: {
  "Id": "0013600000kJhmDAAS",
  "Name": "SomeAccount"
}

It feels to be a bug in SalesForce ... any chance it could be corrected soon ? It's a major blocking problem for our ISV development :/

Here is some code to simply reproduce the problem with a sample app & apex class

Lightning app :

<aura:application controller="ccAppNico">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="Account" type="Account" />

    <a onclick="{!c.doUpdate}">CLICK HERE</a>

</aura:application>

({
    doInit : function(component, event, helper) {
        var action = component.get("c.getAccount");
        AccountName = 'SomeAccount';
        debugger;
        action.setParams({'AccountName':AccountName});
        action.setCallback(this, function(a) {
            debugger;
            var acc = a.getReturnValue();
            component.set("v.Account", acc);
            console.log('AccountFromServer: '+JSON.stringify(acc,null,2));
        });
        $A.enqueueAction(action);
    },

    doUpdate : function(component, event, helper) {
        var action = component.get("c.setAccount"); 
        debugger;
        action.setParams({'acc':component.get('v.Account')});
        action.setCallback(this, function(a) {
            debugger;
            var acc = a.getReturnValue();
            component.set("v.Account", acc);
            console.log('AccountAfterServerTransfer: '+JSON.stringify(acc,null,2));
        });
        $A.enqueueAction(action);
    }
})

Apex controller :

public class ccAppNico {
    @AuraEnabled
    public static Account getAccount(String AccountName)
    {
        List<Account> AccountList = [select Name,(select id,Name from Contacts) from Account where Name=:AccountName limit 1] ;
        Account acc = AccountList[0];
        System.debug(acc);
        System.debug(acc.Contacts);
        return acc ;
    }
    @AuraEnabled
    public static Account setAccount(Account acc)
    {
        System.debug(acc);
        System.debug(acc.Contacts);
        return acc ;
    }    
}

Many many thanks & best regards

0

Doesn't look like you can send objects deeper than 1 level as parameters when calling a server side action. I suggest you send as a string and deserialize in the apex method, or send as separate params.

Rekated issue: https://developer.salesforce.com/forums/?id=906F00000005GiwIAE

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.