0

I am trying to pass a list from lightning controller to apex. My system debug returns records with null values what am I missing? My debug on clientside returns values.

Controller Clientside

saveRecords : function(cmp, event, helper) {
    var act = cmp.get("c.updateInvoices");
    var updatedInvoiceList = cmp.get('v.handleInvoices');
    alert('updatedInvoiceList: ' + updatedInvoiceList[1].selectedOption);
    act.setParams({ "invoices" : updatedInvoiceList});
    $A.enqueueAction(act); 
    alert('DONE');
}

Controller Serverside @AuraEnabled public static void updateInvoices(List<Invocable_Obj_HandleInvoice> invoices){ system.debug('[testHandlInvoice]invoices: ' + invoices); Invocable_Obj_HandleInvoices.HandleInvoices(invoices); }

Debug logs

USER_DEBUG|[34]|DEBUG| [testHandlInvoice]invoices: (Invocable_Obj_HandleInvoice:[availableOptions=null, balanceAmount=null, customerName=null, handlingStatus=null, invoiceId=null, invoiceNumber=null, selectedOption=null, totalAmount=null, zuoraStatus=null], Invocable_Obj_HandleInvoice:[availableOptions=null, balanceAmount=null, customerName=null, handlingStatus=null, invoiceId=null, invoiceNumber=null, selectedOption=null, totalAmount=null, zuoraStatus=null])
USER_DEBUG|[21]|DEBUG| [Invocable_Obj_HandleInvoices]invoices: (Invocable_Obj_HandleInvoice:[availableOptions=null, balanceAmount=null, customerName=null, handlingStatus=null, invoiceId=null, invoiceNumber=null, selectedOption=null, totalAmount=null, zuoraStatus=null], Invocable_Obj_HandleInvoice:[availableOptions=null, balanceAmount=null, customerName=null, handlingStatus=null, invoiceId=null, invoiceNumber=null, selectedOption=null, totalAmount=null, zuoraStatus=null])

UPDATE***

Used:

var updatedInvoiceList = JSON.stringify(cmp.get('v.handleInvoices'));

Apex

   system.debug((List<Invocable_Obj_HandleInvoice>) System.JSON.deserialize(invoices, List<Invocable_Obj_HandleInvoice>.class)); 

ERROR:

FATAL_ERROR|System.JSONException: Expected Map<String,String> but found [line:1, column:3]
  • Could you share your "Invocable_Obj_HandleInvoice" wrapper class? Each attribute in this class would need its own @AuraEnabled annotation to be picked up by the Lightning component, if you haven't set that class up like that already – Instread Aug 17 at 20:00
1

Take a look at this link from developer guide.

I think you cannot pass custom objects as such because the lightning framework would possibly send it on JSON or JS Object literal format and there is no 1-to-1 correction with the input parameter data type in the apex method. You should possibly define the input param in apex as a primitive or a List (or List<List>) or Map<String, String> or a custom apex class. Also, I guess you would need to JSON.stringify before setting the parameter value in the JS controller.

On a different note, never have your @AuraEnabled method returning nothing. Always have a proper return values and capture it in a callback in your JS controller.

| improve this answer | |
  • The apex is a list see: List<Invocable_Obj_HandleInvoice> invoices. In the debug log you can see 2 records (which is correct) are returned but the values are null – Thomas Aug 18 at 10:50
  • That could also mean that apex didn't find the correct mapping between the Invocable_Obj_HandleInvoice & the data that was passed. Could you update your question with the source code for Invocable_Obj_HandleInvoice (if its a wrapper class) and also the sample data that is passed via updatedInvoiceList in the JS file. – arut Aug 18 at 10:58
  • @Thomas, Looks like you were able to solve he problem yourself? I'm curious to know if the problem caused by the format in which you were passing the data from the JS file. – arut Aug 18 at 14:00

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.