【问题标题】:Apex - Invalid return type Map<String, EmbeddedClass>Apex - 无效的返回类型 Map<String, EmbeddedClass>
【发布时间】:2017-07-26 14:27:48
【问题描述】:

我有一个增强自定义按钮功能的 Salesforce Apex 类。我想为前端提供带有信息的键/值对。

我正在苦苦挣扎的是能够保存这个新课程。我收到的错误是:

Invalid return type: Map&lt;String,ButtonCaseHandler.ResponseWrapper&gt; at line 37 column 51

我已经检查过我传递给 ResponseWrapper.value 的所有值都是字符串列表。在这一点上,我不太确定该去哪里。

global class ButtonCaseHandler {

private static final String defaultNewCaseRecordType = 'ID1';

private static List<String> getGhsOpenCases(String memberId, String dependentId){
    List<String> result = new List<String>();
    try{
        //1. check all GHS open cases for this member within the last 14 days
        List<Case> openCases = [
            SELECT Id, casenumber,super_diagnosis__c, CreatedDate
              FROM Case
             WHERE recordTypeId IN ('ID1','ID2')
               AND createdDate >= LAST_N_DAYS:14
               AND status = 'Open'
               AND Account.member_id__c = :memberId
               AND (Account.dependent_id__c = :dependentId OR Account.dependent_id__c = null)
          ORDER BY CreatedDate ASC
        ];

        for(Case c : openCases){
            result.add('Case, '+c.casenumber+', has a super diagnosis of '+ c.super_diagnosis__c + 'and was created on '+ c.createdDate.format('dd-MMM-yyyy'));
        }
    }
    catch(Exception e){
    }

    return result;
}

webService static Map<String,ResponseWrapper> AccountCreateCase(Id aId){
    Map<String, ResponseWrapper> result = new Map<String,ResponseWrapper>();
    try{
        Account currentAccount = [
                                    SELECT Id, Viewing_User_Profile_Name__c, member_id__c, 
                                           Policy__c, Name, dependent_id__c
                                      FROM Account 
                                     WHERE Id = :aId
                                     LIMIT 1
                                ];        

        //create the mapping between profile names and case record types
        Map<String,String> profileNameToReRecordTypeId = new Map<String,String>();
        profileNameToReRecordTypeId.put('RCNAME1','ID1');                                
        profileNameToReRecordTypeId.put('RCNAME2','ID2');
        profileNameToReRecordTypeId.put('System Administrator','ID1');

        String caseRecordType = profileNameToReRecordTypeId.get(currentAccount.Viewing_User_Profile_Name__c);

        if(String.isBlank(caseRecordType)){
            caseRecordType = defaultNewCaseRecordType;
        }

        ///validation if it's a GHS profile
        if(currentAccount.Viewing_User_Profile_Name__c == 'RCNAME1'){
            List<String> ghsOpenCasesString = ButtonCaseHandler.getGhsOpenCases(currentAccount.member_id__c,currentAccount.dependent_id__c);

            if(!ghsOpenCasesString.isEmpty()){
                ResponseWrapper oc = new ResponseWrapper();
                oc.value = ghsOpenCasesString;
                result.put('openCases',oc);
                ResponseWrapper ic = new ResponseWrapper();
                ic.value = new List<String>{'true'};                    
                result.put('invokeConfirm',ic);
            }
        }

        //create the URL hack for the time being. 
        ///we will want to update this later on to create the case and relocate to the newly created case
        String relocateUrl = '/500/e?RecordType=URLTORELOCATETHEUSERTO';

        ResponseWrapper ru = new ResponseWrapper();
        ru.value = new List<String>{relocateUrl}; 
        result.put('relocateUrl',ru);


    }
    catch(Exception e){
        System.debug('Error in AccountCreateCase method: ' + e);
        //instantiate the error long class
        ErrorLog errorLog = new ErrorLog();               
        ErrorLog__c methodErr = new ErrorLog__c(
            method_name__c = 'AccountCreateCase',
            method_source__c = 'ButtonCaseHandler',
            stack_trace__c = e.getMessage(),
            application_data__c = '{"accountId": '+aId+'}'
        );
        errorLog.logError(methodErr, true, '');   
    }

    return result;
}

global class ResponseWrapper {
    webService List<String> value {get; set;}
}    

}

感谢您的帮助。

【问题讨论】:

    标签: salesforce apex


    【解决方案1】:

    该问题是由于当方法是 Web 服务时,不支持将 Maps 作为返回类型。 SOAP 不支持映射,因此您需要转换为列表列表,其中有一个键列表,然后是一个值列表。

    【讨论】:

    • 为什么这甚至是一个WebService?您可以创建一个自定义按钮来启动运行您的逻辑的 Visualforce 页面。
    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 2012-02-07
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    相关资源
    最近更新 更多