0
我有一個Salesforce Apex類,它增強了自定義按鈕的功能。我想提供返回鍵/值對與前端的信息。Apex - 無效的返回類型Map <String,EmbeddedClass>
我正在努力的是能夠得到這個新班保存。我收到的錯誤是:
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;}
}
}
感謝您的幫助。
爲什麼這甚至是WebService?您可以創建一個自定義按鈕來啓動運行您的邏輯的Visualforce頁面。 –