I am calling apex method on lightning:tabClosed event to update a record on closing the tab. I can see the record Id being passed to controller method but query is throwing an error saying
{"exceptionType":"System.QueryException","isUserDefinedException":false,"message":"List has no rows for assignment to SObject","stackTrace":"Class.AccountViewController.updateCustomerInteraction: line 13, column 1"}
Has anyone worked on this kind of functionality before and know why this is happening?
Component:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable" access="global" controller="AccountViewController" >
<lightning:utilityBarAPI aura:id="Accountbar" />
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="interactionId" type="String" />
<aura:attribute name="updatedInteractions" type="vlocity_ins__CustomerInteraction__c" />
<lightning:workspaceAPI aura:id="workspace" />
<aura:handler event="lightning:tabClosed" action="{! c.onTabClosed }"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>
JSController:
({
doInit : function(component, event, helper) {
console.log("Tab Focused");
//SVP-7878 --> START
var workspaceAPI = component.find("workspace");
workspaceAPI.getFocusedTabInfo().then(function(response) {
var focusedTabId = response.tabId;
component.set("v.interactionId",JSON.stringify(response.pageReference.state.vlocity_ins__interactionId));
console.log("Interaction ID params: "+component.get("v.interactionId"));
})
.catch(function(error) {
console.log(error);
});
//SVP-7878 --> END
},
// SVP-7878 POC /START
onTabClosed : function(component, event, helper) {
var currentTabId = event.getParam('tabId');
//console.log("Tab closed: " +currentTabId);
var interIDD = component.get('v.interactionId');
console.log("InteractionId Id in Tab CLosed:: "+interIDD);
var action = component.get("c.updateCustomerInteraction");
action.setParams({"interactionId": interIDD});
action.setCallback(this, function(response) {
var state = response.getState();
if(state == "SUCCESS"){
console.log("IT WORKED!!");
} else {
console.log('There was a problem : '+JSON.stringify(response.getError()));
}
});
$A.enqueueAction(action);
}
// SVP-7878 POC /END
})
APEX CLASS:
public without sharing class AccountViewController {
@AuraEnabled
public static void updateCustomerInteraction(String interactionId){
system.debug('::UPDATECUSTOMERINTERACTION:: ' +interactionId);
vlocity_ins__CustomerInteraction__c CI = [SELECT Id, vlocity_ins__Status__c
FROM vlocity_ins__CustomerInteraction__c
WHERE Id = :interactionId];
CI.vlocity_ins__Status__c = 'Completed';
update CI;
}
}
debug statement in the apex class is getting value of interactionId but query is failing.
UPDATE:
This is working if i pass recordId in the tabClosed event but not a url param. Though the param Id getting passed to Apex method but SOQL is returning empty.