我們已經建立了這個流程來幫助優先考慮我們的案例。要做到這一點,我希望通過電子郵件到個案觸發新案例記錄。然後查詢它是否與帳戶相關。如果是,我想返回一個值,cScore。然後插入。如何在案例記錄成爲案例時訪問案例記錄。 (Email2Case)
這是我迄今爲止,它返回這個錯誤:
Error: Invalid Data. Review all error messages below to correct your data. Apex trigger newCaseScoring caused an unexpected exception, contact your administrator: newCaseScoring: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.newCaseScoring: line 12, column 18
這裏是我的代碼:
觸發newCaseTrigger案例(插入前){
if(Trigger.isInsert){
List<Case> cList = [Select AccountId, Id, Priority_Score__c, Case_Priority_Score__c FROM Case WHERE Id IN :Trigger.new];
List<Case> updateList = [Select AccountId, Id, Priority_Score__c, Case_Priority_Score__c FROM Case WHERE Id IN :Trigger.new];
System.debug('This is the cList:' + cList);
integer size;
integer cnt=0;
List<id> idList = New List<id>();
for(Case cases : cList){
idList.add(cases.AccountId);
size = idList.size();
System.debug('This is the idList:' + idList);
System.debug('This is the size:' + size);
cnt++;
System.debug(cnt);
}
List<Account> aList = [Select Id, Customer_s_Score_Total__c from Account where id =:idList];
integer num;
for(Id a : aList){
for(Id b : idList){
if(aList.Id == idList){
num = aList.Customer_s_Score_Total__c;
updateList.Priority_Score__c = num;
}
}
}
}
}
感謝您的幫助。
謝謝你的經歷。我更新了我的代碼。這不是一個工作模式,我只是想把它扔到那裏,以確保我抓住了這個願景。我做得對嗎? – Havoc783
我不認爲你需要查詢案件。 'for(case cases:cList){'can become'for(Case cases:Trigger.new){'。如果你要爲你的賬戶建立一個Map,你不需要做循環內循環。嘗試'地圖 aMap =新地圖([Select Id,Customer_s_Score_Total__c from Account where IN:idList]);' –
好吧,謝謝,我會試試。謝謝你的幫助! – Havoc783