我有一个Salesforce Apex类,它正在增强自定义按钮的功能。我想提供返回键/值对与前端的信息。
我正在努力的是能够让这个新课程得以保存。我收到的错误是:
Invalid return type: Map<String,ButtonCaseHandler.ResponseWrapper> 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;}
}
}
感谢您的帮助。
答案 0 :(得分:0)
问题是由于当方法是Web服务时,缺少对Maps作为返回类型的支持。 SOAP不支持map,因此您需要转换为列表列表,其中包含键列表,然后是值列表。