Basically, I just want this trigger to update a custom number field (by incrementing it) whenever an email is sent or received from a case.
Here's the trigger:
trigger updateFieldUponEmail on EmailMessage (before insert) {
Set<ID> caseIDs = new Set<ID>();
for(EmailMessage msg : trigger.new){
if(msg.parentID.getsObjectType() == Case.sObjectType)
caseIDs.add(msg.parentID);
}
for(Case c: [SELECT timesUpdated__c FROM Case WHERE Id IN :CaseIDs]){
c.timesUpdated__c++;
}
}
Validates fine, deploys fine. It just doesn't actually increment that field. Not sure why. I tested by sending an email from a case. Am I testing wrong or is the code wrong?
update caseList