We've set up this process to help prioritize our cases. To do this, I want to trigger off a new case record after it comes in through email-to-case. Then query to see if it's related to an account. If it is, I want to return a value, cScore. Then insert.
This is what I have so far, it's returning this error:
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
Here's my code:
trigger newCaseTrigger on Case (before insert) {
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;
}
}
}
}
}
Thanks for the help.