You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Salesforce Aura组件Helper无法调用重命名后的Apex类方法

重命名Apex控制器后Aura组件无法调用方法的问题

问题背景

已完成以下重命名操作:

  • 将Apex控制器类名从CRSController改为TRSController
  • 将变量名lstCRSContacts改为lstTRSContacts

但修改后,Aura组件的Helper类无法调用TRSController中的initMethod方法。调试时发现Apex日志仅输出CODE_UNIT_STARTED和CODE_UNIT_FINISHED,即使添加System.debug语句也没有其他日志内容。

相关代码

Aura组件代码

<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>计划联系人 ({!v.recordCount})</b></h2> </div></td>
        </table>
    </aura:attribute> 
</aura:component>

JavaScript控制器代码

({
    doInit: function(component, event, helper) { 
        console.log("进入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"){
                // 错误表示调用Apex控制器时服务器端出现问题
                let toastParams = {
                    title: "错误",
                    message: "获取计划联系人时发生错误。", 
                    type: "error",
                    duration: '30000',
                    key: 'info_alt',
                    mode: 'pester'
                };
                // 触发错误提示弹窗
                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>();
        // 由Sravanthi Talakanti添加结束日期筛选条件,仅在资产Lightning页面显示活跃资产
        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]){
               
                // 如果当前记录的联系人ID与上一条相同,则将当前记录的联系人类型追加到上一条记录中,不添加当前记录
                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;    
    }
    
    // 内部类
    public class wrapperClass{
        @AuraEnabled public List<AssetContact__c> lstTRSContacts{get;set;}
        @AuraEnabled public Id caseRecordType{get;set;}
    }
}

内容的提问来源于Stack Exchange,提问作者Balaji

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 17:44:56