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
Vinicius Damasceno 1Vinicius Damasceno 1 

Action.setCallback not being executed event tabclosed lightning component

I have an issue where in my action.setCallBack is not being run.
When user closes the tab, the component call a function onTabClosed.
onTabClosed : function(component, event, helper) {
var aCaseId = component.get("v.recordId");
console.log('yep');
var action = component.get("c.hasCustomerInteractionOpenA");
action.setParams({aCaseId : aCaseId});
action.setCallback(this, function(response) {
console.log('callBack');
var state = response.getState();
var result = response.getReturnValue();
//console.log('BKO Picklist values ' +JSON.stringify(result));
if (state === "SUCCESS") {
console.log('test1');
component.set("v.checkTab",true); }
else{
console.log('test2');
component.set("v.checkTab",true);
} });
$A.enqueueAction(action);

console.log('yep1'); },


The console.log inside callBack is not being executed. Only the console.log(yep1) and (yep2).


Here is the Apex:
@AuraEnabled public static Boolean hasCustomerInteractionOpen(String aCaseId){

try{
Case lCase = [SELECT AttendanceProtocol__c, Id, Status, AttendanceProtocol__r.LastModifiedDate, AttendanceProtocol__r.vlocity_cmt__Status__c, OwnerId FROM Case WHERE Id =: aCaseId LIMIT 1];
if((String.isNotBlank(lCase.AttendanceProtocol__c)) && (lCase.AttendanceProtocol__r.vlocity_cmt__Status__c != 'Closed') && (lCase.OwnerId == (UserInfo.getUserId()))){

List<Case> lCaseCustomer = [SELECT Id,AttendanceProtocol__c, Status, ClosedDate FROM Case WHERE AttendanceProtocol__c =: lCase.AttendanceProtocol__c ORDER BY ClosedDate DESC];

if((lCaseCustomer[0].Id == lCase.Id) && ((lCase.AttendanceProtocol__r.LastModifiedDate) < (lCaseCustomer[0].ClosedDate))){

System.debug('true'); return true; }
} System.debug('false');
return false;
}catch(Exception e){ System.debug('The following exception has occurred: ' + e.getMessage()); return false; } }


The system.debug is returning in the debugging. So, the apex is being called, returning a value.
But the action.setCallBack is not accessing this value. I'm on it has two days, someone can help me? Really appreciate it.
mukesh guptamukesh gupta
Hi Vini,

Please use below code in your component it will be work:-
 
onTabClosed : function(component, event, helper) {
var aCaseId = component.get("v.recordId");
console.log('yep');
var action = component.get("c.hasCustomerInteractionOpen");
action.setParams({aCaseId : aCaseId});
action.setCallback(this, function(response) {
console.log('callBack');
var state = response.getState();
var result = response.getReturnValue();
//console.log('BKO Picklist values ' +JSON.stringify(result));
if (state === "SUCCESS") {
console.log('test1');
component.set("v.checkTab",true); }
else{
console.log('test2');
component.set("v.checkTab",true);
} });
$A.enqueueAction(action);

console.log('yep1'); }
if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
Vinicius Damasceno 1Vinicius Damasceno 1
Sorry, I had switched to "hasCustomerInteractionOpenA" to run a test. But it's already correct again and still with the same problem