You need to sign in to do that
Don't have an account?
Allen2
Case assignment rules are not firing based on toAddress of incoming mail on cases
I've written the below code to update the field on case object when we're getting email to case. But when I tried to write logic to fire case assignment rule based on whatever value we're having in emailMessae.toAddress, it's not working at all.
Can any one please help me out on this?
Public class emailMessageHelper { Public static void updateCase (list<EmailMessage> newEmailMessageList, map<Id, EmailMessage> oldMap){ Set <Id> caseIdSet = new Set <Id>(); list <Case> caseList = new List <Case>(); Map<Id, Case> caseMap = new Map<Id, Case>(); list<Case> newCaseList = new list<Case>(); for (EmailMessage messageObj: newEmailMessageList) { caseIdSet.add(messageObj.ParentId); } if(caseIdSet.size()>0) { caseList=[Select Id, OwnerId, Owner.Email, Status, status_Alert__c from case where Id in :caseIdSet]; for(case caseObj: caseList) { caseMap.put(caseObj.Id,caseObj); } } for (EmailMessage messageObj: newEmailMessageList){ Case caseObj = caseMap.get(messageObj.ParentId); caseObj.Source_Email__c = MessageObj.ToAddress; System.debug('messageObj.ToAddress abc '+messageObj.ToAddress); if(caseObj.status !='New' && caseObj.Status_Alert__c != 'New Email Received' && messageObj.incoming && messageObj.toAddress!= null ){ caseobj.status_Alert__c = 'New Email received'; Database.DMLOptions dmlOpts = new Database.DMLOptions(); dmlOpts.assignmentRuleHeader.useDefaultRule= true; caseobj.setOptions(dmlOpts); newCaseList.add(caseObj); } else if(!messageObj.incoming){ caseobj.status_Alert__c = ''; newCaseList.add(caseObj); } } if(newCaseList.size() > 0){ update newCaseList; } } }I'm calling the method in After insert and After update context.
Can any one please help me out on this?
Just a idea have you tried checking if the assigment rules are running normally using the debug logs??
Regards,
Anutej
Thanks!
Allen