SaveAccessRequest : function(component, event, helper) {
var ARLIlist = component.get("v.AccessRequestLineItems");
var action = component.get("c.getSaveRecord");
var accessreq = component.get("v.AccessRequest");
action.setParams({"AR":accessreq,
"ARLI":ARLIlist});
$A.enqueueAction(action);
}
Here "AccessRequestLineItems" & "AccessRequest" is an sobject array & sobject defined on the component. while I invoke this function neither received an error nor the function on apex is invoked. can anyone help me in resolving the issue?
Apex code
@AuraEnabled
public static void getSaveRecord(Access_Request__c AR,List<Access_Request_Line_Item__c> ARLI){
system.debug('====>'+ARLI);
Insert AR;
system.debug('====>'+ARLI);
for(Integer i=0; i<ARLI.size(); i++){
ARLI[i].Access_Request_ID__c = AR.id;
}
Insert ARLI;
system.debug('====>'+ARLI[0].id);
}
Also tried with return type
@AuraEnabled
public static Access_Request__c getSaveRecord(Access_Request__c AR,List<Access_Request_Line_Item__c> ARLI){
system.debug('====>'+ARLI);
Insert AR;
system.debug('====>'+ARLI);
for(Integer i=0; i<ARLI.size(); i++){
ARLI[i].Access_Request_ID__c = AR.id;
}
Insert ARLI;
system.debug('====>'+ARLI[0].id);
return AR;
}
Best Answer
Take a look at this post. I was able to pass the sobject and sobject array using json.encode util.I have used account sobject for the sake of testing.
Passing a sobject param was/ is causing error in Lightning: https://success.salesforce.com/issues_view?id=a1p300000008XW6AAM
component:
controller: I have queried the account list and passed it to the getReturnValue method in the server side controller.
Apex controller:
Debug logs:
09:38:31.3 (4142574)|USER_DEBUG|[4]|DEBUG|====>[{"Id":"001d000001xDnrmAAC","Name":"Smith Enterprises"},{"Id":"001d0000026DD5JAAW","Name":"test"},{"Id":"001d000001StO98AAF","Name":"abc"},{"Id":"001d000001StOT1AAN","Name":"abc"},{"Id":"001d000000ySkIvAAK","Name":"TEST"}] 09:38:31.3 (4172328)|STATEMENT_EXECUTE|[5] 09:38:31.3 (4180526)|HEAP_ALLOCATE|[5]|Bytes:44 09:38:31.3 (4189407)|ENTERING_MANAGED_PKG| 09:38:31.3 (4198943)|USER_DEBUG|[5]|DEBUG|====>{"sobjectType":"Account","Name":"test"}