SHARE
TWEET

Untitled

a guest Jun 27th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trigger identifyLastEmailMessage on EmailMessage (after insert, after update) {
  2.     List<EmailMessage> emailThatStartedTrigger = new List<EmailMessage>();
  3.     emailThatStartedTrigger = Trigger.new;
  4.     system.debug('Case Id: ' + emailThatStartedTrigger[0].ParentId);
  5.     List<EmailMessage> allEmailsRelatedToThisCase = new List<EmailMessage>();
  6.     allEmailsRelatedToThisCase = [select Id, Last_Email_for_Case__c, CreatedDate from EmailMessage where ParentId = :emailThatStartedTrigger[0].ParentId ORDER BY CreatedDate ASC];
  7.  
  8.     if (Trigger.isAfter) {
  9.  
  10.         for (integer i =0; i< allEmailsRelatedToThisCase.size(); i++) {
  11.             if (i == 0) {
  12.                 allEmailsRelatedToThisCase[i].Last_Email_for_Case__c = true;
  13.             }
  14.             else {
  15.                 allEmailsRelatedToThisCase[i].Last_Email_for_Case__c = false;
  16.             }
  17.  
  18.         }
  19.  
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top