Created
October 23, 2018 22:16
-
-
Save melissajhansen/bc39766f4e4c146b3282bcb718499873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class ContactTriggerHandlerV3 { | |
//Has the Contact trigger already executed? | |
public static boolean hasExecuted = false; | |
//Variables to store Trigger.oldMap & Trigger.newMap | |
Map<ID, Contact> oldContactsMap; | |
Map<ID, Contact> newContactsMap; | |
public ContactTriggerHandlerV3(Map<ID, Contact> oldTriggerContacts, Map<ID, Contact> newTriggerContacts) { | |
oldContactsMap = oldTriggerContacts; | |
newContactsMap = newTriggerContacts; | |
} | |
//Handler Methods | |
public void onBeforeInsert() { | |
} | |
public void onAfterInsert() { | |
} | |
public void onBeforeUpdate() { | |
} | |
//After a Contact is updated, check to see if it has an associated account and an email address | |
//Contacts without these are often junk. If they are missing either, create a case so that someone looks into it | |
public void onAfterUpdate() { | |
//create a list to hold any new cases we may create | |
List<Case> newCases = new List<Case>(); | |
//Now go through each Contact and see if they need a case | |
for (Contact c : newContactsMap.values()) { | |
if (c.AccountId == NULL && c.Email == NULL) { | |
System.debug('noAccount&NoEmail'); | |
Case cse = new Case(); | |
cse.Status = 'New'; | |
cse.Origin = 'Questionable Contact'; | |
cse.Subject = 'Clean up Contact Record'; | |
cse.ContactId = c.Id; | |
cse.Description = 'This contact is not attached to an account and does not have an email address. Is it needed?'; | |
newCases.add(cse); | |
} | |
} | |
insert newCases; | |
} | |
public void onBeforeDelete() { | |
} | |
public void onAfterDelete() { | |
} | |
public void onUndelete() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment