I have a email to case. Once an email is received from a service address , a case gets created and the issue is that trigger is not getting fired. I cross checked with a workflow rule, the workflow rule is able to work properly when an email is received. I have created a workflow on email message Object. But trigger is not working
trigger EmailResponse on EmailMessage (after insert) {
//Boolean custResp;
Datetime theDate;
set<Id> caseIds = new set<Id>();
map<Id,Datetime> case2CustomValueMap = new map<Id,Datetime>();
for(EmailMessage message : trigger.new){
if(message.Incoming == true){
system.debug('.....EMAIL RECEIVED');
//Some sort of logic that gets the value for this
theDate = message.MessageDate;
system.debug('.....theDate '+theDate);
}
/*
else
custResp = False;
if(Trigger.isUpdate){
system.debug('Update happened');
custResp = FALSE;
}
*/
caseIds.add(message.ParentId);
case2CustomValueMap.put(message.ParentId, theDate);
//case2CustomValueMap2.put(message.ParentId, custNoResp);
}
list<Case> casesToUpdate = [Select Id, LastModifiedDate, CreatedDate, Last_Date_time_when_email_occurred__c From Case Where Id in: caseIds];
for(Case c : casesToUpdate){
//c.RESP__c = case2CustomValueMap.get(c.Id);
c.Last_Date_time_when_email_occurred__c = case2CustomValueMap.get(c.Id);
system.debug('.....Last Date time ' +c.Last_Date_time_when_email_occurred__c);
//if(Trigger.oldMap.get(c.Id).LastModifiedDate != c.LastModifiedDate)
// c.Customer_Response__c = FALSE;
}
update casesToUpdate;
}
I'm unable to capture it even in Debug Logs. Trigger is fine. But trigger is not getting fired . Please help.
custResp
is commented out