Guest User

Untitled

a guest
Oct 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. public static void uniqueRelationshipOwnerEmails(List<relationship_owner__c> roList){
  2. //count the unique emails that have been sent by a relationship owner
  3. // add all contacts associated with relationship owner to map.
  4. Map<id, Contact> contactMap = new Map<Id, Contact>([SELECT Id,
  5. New_Relationship_Owner1__c
  6. FROM Contact
  7. WHERE New_Relationship_owner1__c IN : roList]);
  8. system.debug('Contacts found = ' + contactMap.size());
  9. //put tasks where whoId is in the contact map into a new map
  10. List<Task> taskList = [SELECT Id, WhoId,Subject
  11. FROM Task
  12. WHERE WhoId IN :contactMap.keySet()
  13. AND Subject LIKE '%Pardot List Email%'];
  14. system.debug('Tasks Found and added to map = ' + taskList.size());
  15. //use set to dedupe the list
  16. Map<Id, Set<String>> subjectLineMap = new Map<Id, Set<String>>();
  17.  
  18. for(task t : taskList){
  19. Id ownerId = contactMap.get(t.WhoId).New_Relationship_Owner1__c;
  20. if(!subjectLineMap.containsKey(ownerId)){
  21. subjectLineMap.put(ownerId, new Set<String>());
  22.  
  23. }
  24. }
  25. system.debug('Map size =' + subjectLineMap.size());
  26. system.debug('map values =' + subjectLineMap.values());
  27. system.debug('map keys =' + subjectLineMap.Keyset());
  28. for(relationship_owner__c r : roList){
  29. r.Unique_Emails_Sent__c = subjectLineMap.get(r.Id).size();
  30. roList.add(r);
  31.  
  32. }
  33. insert(roList);
  34.  
  35.  
  36.  
  37. }
  38.  
  39. @isTest
  40. static void uniqueEmailTest(){
  41. TestDataFactory.createRelationshipOwnerandInfuencer(5, 1);
  42. List<relationship_owner__C> ownerTestList = [SELECT id, Unique_Emails_Sent__c From relationship_owner__c];
  43. //update ownerTestList;
  44. //get the contacts and assign them tasks
  45. List<Contact> influencers = [SELECT Id FROM Contact];
  46. List<Task> tasks = new List<Task>();
  47. for(Contact c : influencers){
  48. Task t = new Task(Subject = 'Pardot List Email 1', WhoId = c.Id);
  49. tasks.add(t);
  50. }
  51. insert tasks;
  52. system.debug('task size' + tasks.size());
  53. update ownerTestList;
  54. }
Add Comment
Please, Sign In to add comment