Hi I have a requirement. I have a custom Checkbox field inside case object say "res__c". When a Email is received then this res__c should be TRUE. And later if the case record is edited, then res__c should be false. So, i have written a after insert trigger on EmailMessage. Here i have mapped EmailMessage.ParentID and Boolean value.. Once an email is received, that is,
for(EmailMessage Email : Trigger.New) {
IF(Email.Incoming == TRUE)
res__c = true;
// added email.parentID and res__c to the map
}
Since the trigger is running on EmailMessage object, i cannot write a before update trigger on Case object. So i wrote a Workflow.. IN this workflow, action is ISCHANGED(LastModifiedDate)
and field update that res__c = false. Now, what am facing is that when a new email arrives, both Trigger and Workflow performs at the same time and the final value on the res__c is becoming false. I checked the trigger and it gives 100% code coverage and Update happens on the res__c when a mail is received and it returns true. But at the same ISCHANGED() function is also running on the INSERT of record itself. I think that ISCHANGED() function runs on insert because the Lastmodified Date value for a record is null and its being changed to a value of NOW() on the creation of record.
So please provide me an idea of how to resolve this,
- should i try something like
Datetimevalue(LastmodifiedDate)-Datetimevalue(CreatedDate)<>0
for workflow action (or) - Should i write a trigger on case object to uncheck the res__c value on any update for the record (or)
- will i be able to check for change in case record value on the after insert trigger of Emailmessage itself.