function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bryan Leaman 6Bryan Leaman 6 

Aura component combined requests only 1 gets a result

I've noticed issues with the lightning framework when multiple requests are combined. I'm working on a new quickAction lightning aura component and I'm issuing 2 calls to my controller for 2 different pieces of information. When the lightning framework combines the requests into a single call to the server I can see both responses in the return payload (using Chrome developer tools), but only 1 of my method calls' callback functions gets invoked. The other does not, so I cannot access the returned data.

I've had to cascade my method calls so the second one is invoked when the first one completes. Then when the second one completes I can access its return data.

Note, I'm using aura because (as far as I can tell) lightningQuickAction isn't available in lwc yet.

(As a side note: I've noticed incomplete native components like today's tasks or list views on my home page don't always get filled in if the requests get combined as well.)
MagulanDuraipandianMagulanDuraipandian
You should be fine with two $A.enqueueAction(action) methods. As a best practice to avoid apex execution and to avoid concurrent apex exception, you should combine both the apex server calls into a single call.
--
Magulan Duraipandian
https://www.infallibletechie.com/
Bryan Leaman 6Bryan Leaman 6
I agree that I *should* be fine with 2 $A.enqueueAction(action) methods, but I'm not. If I invoke one in the success block of the other's call-back it works every time, but I shouldn't have to do that. The two routines really do two different things.
 
...  // If I do this in the controller, then one of the two callback's doesn't get called even though I see both results in the Chrome console, combined from 1 server request:
helper.loadReferencedColumnNames(component);
helper.loadCsvData(component);
...
 
... // This is in the helper logic: I eliminated the non-success handling to simplify the code shown ...

    // Find all csv column names referenced in the Task Assignment Upload request
    loadReferencedColumnNames : function(component) {
        console.log('loadReferencedColumnNames');
        let method = component.get('c.findColumnHeadingReferences');
        method.setParams({taskAssignmentUploadId : component.get('v.recordId')});
        method.setCallback(this, function(response) {
            console.log('findColumnHeadingReferences response');
            let state = response.getState();
            if (state==='SUCCESS') {
                let returnval = response.getReturnValue();
                console.log('findColumnHeadingReferences returnval = ' + JSON.stringify(returnval)); 
                component.set('v.columnReferences', returnval);
            }
        });
        console.log('call findColumnHeadingReferences');
        $A.enqueueAction(method);
        console.log('done calling findColumnHeadingReferences');
    },

    // Find the csv file and return the data it contains as a map
    loadCsvData : function(component) {
        console.log('loadCsvData');
        let method = component.get('c.loadCsvDataAsLists');
        method.setParams({taskAssignmentUploadId : component.get('v.recordId')});
        method.setCallback(this, function(response) {
            console.log('loadCsvDataAsLists response');
            let state = response.getState();
            if (state==='SUCCESS') {
                let returnval = response.getReturnValue();
                console.log(returnval.length);
                component.set('v.csvData', returnval);
            }
        });
        console.log('call loadCsvDataAsLists');
        $A.enqueueAction(method);
        console.log('done calling loadCsvDataAsLists');
    },