I have a requirement where I need to change the text of any class from CRS to TRS. We have an apex controller called CRSController and I renamed it to TRSController. This apex method is getting called from a helper class of an Aura component. However, after renaming the apex controller, the method in the Apex controller is not getting invoked from the helper class.
Below is my code set.
Aura Component:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:appHostable" access="global" controller="TRSController">
<aura:attribute name="planContacts" type="List" />
<aura:attribute name="recordsReturned" type="Integer"/>
<aura:attribute name="recordCount" type="String" default="0"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="headerTitle" type="Aura.Component[]">
<table style="width:100%">
<td><div align="left"><h2><b>Plan Contacts ({!v.recordCount})</b></h2> </div></td>
</table>
</aura:attribute>
</aura:component>
JavaScript Controller:
({
doInit: function(component, event, helper) {
console.log("IN DOINIT @@@@@@@@@@@");
helper.getPlanContacts(component);
},
})
JavaScript Helper:
({
getPlanContacts : function(component) {
var action = component.get('c.initMethod');
//var self = this;
action.setParams({
planId : component.get("v.recordId")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var records =response.getReturnValue().lstTRSContacts;
records.forEach(function(record){
record.linkName = '/lightning/r/contact/' +record.Contact__c + '/view';
});
component.set('v.planContacts', records);
component.set('v.recordCount',response.getReturnValue().lstTRSContacts.length);
}
else if(state==="ERROR"){
//Error indicates a problem on server side when calling the apex controller.
let toastParams = {
title: "Error",
message: "Error occured when retrieving Plan Contacts. ",
type: "error",
duration:' 30000',
key: 'info_alt',
mode: 'pester'
};
// Fire error toast
let toastEvent = $A.get("e.force:showToast");
toastEvent.setParams(toastParams);
toastEvent.fire();
}
});
$A.enqueueAction(action);
},
})
Apex Controller:
public class TRSController {
@AuraEnabled
public static wrapperClass initMethod(id planId){
wrapperClass returnWrapperClass = new wrapperClass ();
integer index = 0;
id contactid;
list<ASTContact__c> returnList = new list<ASTContact__c>();
// added filter for endate to show only active assets on asset lightning page by sravanthi talakanti
for(ASTContact__c ac : [Select Contact__r.Name,Contact__r.Phone,Contact__r.Email,Id,ContactType__c,IsPrimaryContact__c,Contact__c
from ASTContact__c
where Asset__c = :planId and (enddate__c >= today or enddate__c = null)
order by Contact__r.LastName,Contact__c]){
//If contact id matches the previous contact id then append the contact type from the current
//record to the previous record and don't add the current record.
if(ac.Contact__c == contactId){
returnList[index-1].ContactType__c = returnList[index-1].ContactType__c + '</br>' + ac.ContactType__c;
If(ac.IsPrimaryContact__c){
returnList[index-1].isPrimaryContact__c = true;
}
}
else{
returnList.add(ac);
index = index +1;
}
contactid = ac.Contact__c;
}
returnWrapperClass.lstTRSContacts = returnList;
returnWrapperClass.caseRecordType = Schema.SObjectType.Asset.getRecordTypeInfosByDeveloperName().get('TRS').getRecordTypeId();
return returnwrapperClass;
}
// Inner class
public class wrapperClass{
@AuraEnabled public List<AssetContact__c> lstTRSContacts{get;set;}
@AuraEnabled public Id caseRecordType{get;set;}
}
}
The only change I did was to rename the Apex class from CRSController to TRSController and changed the variable name from lstCRSContacts to lstTRSContacts in the code.
I did try to debug, but could not figure out the issue. In apex debug log, I see the mess CODE_UNIT_STARTED and CODE_UNIT_FINISHED for the apex method initMethod(), but no other debug log messages are getting printed even if I place some system.debug messages in the code.
Can someone help?
Thanks in advance.