You need to sign in to do that
Don't have an account?
Srinivas Shettigar
Server-side controller action $A.enqueueAction(action) is not calling the back end call
I am using Lightning frame to render d3 type of spider view UI, on click of nodes in the spider view, I am supposed to make as APEX call to fetch the JSON data to render the node. I have earlier called server side code using $A.enqueueAction(action), but when I perform the same within my filestore java script action.setCallback does not get called, it looks as if it has hit a dead lock. I have noticed one more behavior if I force the code to throw an exception the call-back gets called. It looks like Lightning framework has some limitation while making an asynchronous calls with in non-blocking function calls. I am attaching the code with 3 scenariosfor your perusal, if you could help me understand the behaviors of the code that will be of great help.
Scenario A : lightningAction.setCallback does not get called. var paramss= JSON.stringify(params); var deferred = $.Deferred(); var lightningAction = lightningComponent.get("c.invokeAppToolKitGet"); lightningAction.setParams({ "parameters": paramss }); lightningAction.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var calloutRes = response.getReturnValue(); var callBackResponse = JSON.parse(calloutRes); callBackResponse.data.data.entity = JSON.stringify(callBackResponse.data.data.entity); deferred.resolve(callBackResponse); } else{ deferred.reject('Error'); } }); $A.enqueueAction(lightningAction); var promise = deferred.then(function(response) { //Parse the response and build the node object } return promise;
Scenario B : Introduced $A.getCallback that throws an exception, with this change the call back get called, but the main code breaks since remaining code was not processed due to exeption. var paramss= JSON.stringify(params); var deferred = $.Deferred(); var lightningAction = lightningComponent.get("c.invokeAppToolKitGet"); lightningAction.setParams({ "parameters": paramss }); lightningAction.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var calloutRes = response.getReturnValue(); var callBackResponse = JSON.parse(calloutRes); callBackResponse.data.data.entity = JSON.stringify(callBackResponse.data.data.entity); deferred.resolve(callBackResponse); } else{ deferred.reject('Error'); } }); $A.enqueueAction(lightningAction); $A.getCallback(function() { }); var promise = deferred.then(function(response) { //Parse the response and build the node object } return promise;
Scenario C : The call back does not get called. Since we catch the exception and main code gets processed and call back in not getting called. It looks like Thread locking scenario in Java. var paramss= JSON.stringify(params); var deferred = $.Deferred(); var lightningAction = lightningComponent.get("c.invokeAppToolKitGet"); lightningAction.setParams({ "parameters": paramss }); lightningAction.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var calloutRes = response.getReturnValue(); var callBackResponse = JSON.parse(calloutRes); callBackResponse.data.data.entity = JSON.stringify(callBackResponse.data.data.entity); deferred.resolve(callBackResponse); } else{ deferred.reject('Error'); } }); $A.enqueueAction(lightningAction); try{ $A.getCallback(function() { }); catch(error){ log.error("Dummy", "Error " + error); } var promise = deferred.then(function(response) { //Parse the response and build the node object } return promise;
What context is the code in the above scenarios running in (controller/helper)? Also what do you mean by using a Lightning frame?
The code is running in Controller context, the controller call the FileStore script which is included as static resource, and with-in the FileStore script i am facing this issue.
I mean Lighthing Component framework, in the Lightning Component Developers pdf it talks about frame, my understaing was it has to do with Lighthing Component framework.
Did you find any solution, I have a same issue.
My working code...
var file = fileList[0];
var fileReader = new FileReader();
fileReader.onload = $A.getCallback(function() {
action.setCallback(.....
$A.enqueueAction(.....
});
fileReader.readAsDataURL(file);