Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void uniqueRelationshipOwnerEmails(List<relationship_owner__c> roList){
- //count the unique emails that have been sent by a relationship owner
- // add all contacts associated with relationship owner to map.
- Map<id, Contact> contactMap = new Map<Id, Contact>([SELECT Id,
- New_Relationship_Owner1__c
- FROM Contact
- WHERE New_Relationship_owner1__c IN : roList]);
- system.debug('Contacts found = ' + contactMap.size());
- //put tasks where whoId is in the contact map into a new map
- List<Task> taskList = [SELECT Id, WhoId,Subject
- FROM Task
- WHERE WhoId IN :contactMap.keySet()
- AND Subject LIKE '%Pardot List Email%'];
- system.debug('Tasks Found and added to map = ' + taskList.size());
- //use set to dedupe the list
- Map<Id, Set<String>> subjectLineMap = new Map<Id, Set<String>>();
- for(task t : taskList){
- Id ownerId = contactMap.get(t.WhoId).New_Relationship_Owner1__c;
- if(!subjectLineMap.containsKey(ownerId)){
- subjectLineMap.put(ownerId, new Set<String>());
- }
- }
- system.debug('Map size =' + subjectLineMap.size());
- system.debug('map values =' + subjectLineMap.values());
- system.debug('map keys =' + subjectLineMap.Keyset());
- for(relationship_owner__c r : roList){
- r.Unique_Emails_Sent__c = subjectLineMap.get(r.Id).size();
- roList.add(r);
- }
- insert(roList);
- }
- @isTest
- static void uniqueEmailTest(){
- TestDataFactory.createRelationshipOwnerandInfuencer(5, 1);
- List<relationship_owner__C> ownerTestList = [SELECT id, Unique_Emails_Sent__c From relationship_owner__c];
- //update ownerTestList;
- //get the contacts and assign them tasks
- List<Contact> influencers = [SELECT Id FROM Contact];
- List<Task> tasks = new List<Task>();
- for(Contact c : influencers){
- Task t = new Task(Subject = 'Pardot List Email 1', WhoId = c.Id);
- tasks.add(t);
- }
- insert tasks;
- system.debug('task size' + tasks.size());
- update ownerTestList;
- }
Add Comment
Please, Sign In to add comment