15

My Lightning Component controller:

doActivateNext : function(component, event, helper) {
    var action = component.get("c.activateNext");
    action.setParams({ bpiId : component.get("v.recordId"), 
                       stages : component.get("v.stages") });
    ...
}

calls this @AuraEnabled Apex method:

public static void activateNext(Id bpiId, List<BpiStage> stageList) {
    System.debug(stageList); // I see a non-empty list in the logs

    for(BpiStage stage : stageList) {
        System.debug(stage); // Fails before outputt
    }
}

The System.debug() in line 3 perfectly prints a list of objects of the BpiStage class. But as soon stages is access in the for loop (or any other method like .isEmpty() or .get(0) or [0]) the code fails with a:

11:55:45:030 FATAL_ERROR System.UnexpectedException: Salesforce System Error: 1261878509-48218 (152924272) (152924272)

What is going on here?

7
  • 1
    Looks weird, can you try passing the list as JSON string and deserialize it in controller?
    – Praveen
    Oct 21, 2016 at 10:23
  • I expected Lightning to do that for me...How would I do that? I am Lightning newbie ;-) Oct 21, 2016 at 10:31
  • 1
    Is the problem a mismatch in types where stages is a list<BpiStage> and the loop is iterating over a list<BpiChevronStage>? I'm surprised the Apex compiler would have even allowed that in the first place.
    – martin
    Oct 21, 2016 at 10:42
  • @martin: No this was just a copy and past error inside of Stackexchange... Corrected it. Oct 21, 2016 at 10:43
  • 1
    Convert the array to string using JSON.stringify. So stages : JSON.stringify(component.get("v.stages")). Try deserializing the string to List< BpiStage> in the controller.
    – Praveen
    Oct 21, 2016 at 10:46

1 Answer 1

11

Looks weird,might be a bug. As a workaround, try passing the stages array as string from the component and deserialize the string to List<BpiStage> in the apex controller.

Controller.js

ction.setParams({ bpiId : component.get("v.recordId"), 
                  stages : JSON.stringify(component.get("v.stages")) });

AuraMethod:

public static void activateNext(Id bpiId, String stageStr) {
    List<BpiStage> stageList = (List<BpiStage>)JSON.deserialize(stageStr,List<BpiStage>.class)
    System.debug(stageList);

    for(BpiStage stage : stageList) {
        System.debug(stage);
    }
}
2
  • 3
    The same workaround was proposed by Salesforce Support in Case 14941232. I asked them to file a Know Issue for it so we can keep track. Oct 21, 2016 at 12:21
  • There is no Know Issue for that yet but you can log a ticket with salesforce mentioning the same Bug number - W-3159538 to know the status. Oct 21, 2016 at 14:51

You must log in to answer this question.

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