我有一个要求,需要将任何课程的文本从 CRS 更改为 TRS。我们有一个名为 CRSController 的顶点控制器,我将其重命名为 TRSController。这个 apex 方法是从 Aura 组件的辅助类中调用的。但是,重命名 apex 控制器后,不会从辅助类中调用 Apex 控制器中的方法。
下面是我的代码集。
光环成分:
<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 控制器:
({
doInit: function(component, event, helper) {
console.log("IN DOINIT @@@@@@@@@@@");
helper.getPlanContacts(component);
},
})
JavaScript 助手:
({
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 控制器:
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;}
}
}
我所做的唯一更改是将 Apex 类从 CRSController 重命名为 TRSController,并将代码中的变量名称从 lstCRSContacts 更改为 lstTRSContacts。
我确实尝试过调试,但无法找出问题所在。在 apex 调试日志中,我看到 apex 方法 initMethod() 的 CODE_UNIT_STARTED 和 CODE_UNIT_FINISHED 混乱,但即使我在代码中放置一些 system.debug 消息,也不会打印其他调试日志消息。
有人可以帮忙吗?
提前致谢。
终于我弄清楚了这个问题。更改 apex 类名称后,测试用户的配置文件没有访问 apex 类的权限。一旦我在测试用户的配置文件中向 apex 类 TRSController 提供了权限,它就开始工作了。