Skip to content

Instantly share code, notes, and snippets.

@pcave
Created July 31, 2015 19:36
Show Gist options
  • Save pcave/7b9bb359305e237c0e32 to your computer and use it in GitHub Desktop.
Save pcave/7b9bb359305e237c0e32 to your computer and use it in GitHub Desktop.
Ugly Apex
trigger ActionsTakenTriggerHandler on jrsbd__sb_Actions_Taken__c (after insert) {
Map<Id, Integer> actionsTaken = new Map<Id, Integer>();
Map<Id, Integer> petitionsSigned = new Map<Id, Integer>();
Map<Id, Integer> actionsLast30Days = new Map<Id, Integer>();
// Figure out how many actions taken and petitions signatures are going to be added to each Contact.
for (jrsbd__sb_Actions_Taken__c actionTaken: Trigger.new) {
if (actionTaken.jrsbd__Action_Type__c == 'Petition') {
if (petitionsSigned.containsKey(actionTaken.jrsbd__Contact__c)) {
petitionsSigned.put(actionTaken.jrsbd__Contact__c, petitionsSigned.get(actionTaken.jrsbd__Contact__c) + 1);
}
else {
petitionsSigned.put(actionTaken.jrsbd__Contact__c, 1);
}
}
else if (actionTaken.jrsbd__Action_Type__c == 'Message Action') {
if (actionsTaken.containsKey(actionTaken.jrsbd__Contact__c)) {
actionsTaken.put(actionTaken.jrsbd__Contact__c, actionsTaken.get(actionTaken.jrsbd__Contact__c) + 1);
}
else {
actionsTaken.put(actionTaken.jrsbd__Contact__c, 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment