diff --git a/src/main/default/classes/MassEmailController.cls b/src/main/default/classes/MassEmailController.cls index be727923..f6f367d1 100644 --- a/src/main/default/classes/MassEmailController.cls +++ b/src/main/default/classes/MassEmailController.cls @@ -54,7 +54,7 @@ public with sharing class MassEmailController { Id orgWideAddrId = NULL; Id blaRecord = NULL; Map> contactContentVerMap = new Map>(); - List contacts =new List(); + Map contacts = new Map(); try { //fetch acc status and rec type from metadata @@ -114,7 +114,7 @@ public with sharing class MassEmailController { blaContactMap.put(blaRecord,new List()); } - for(AccountContactRelation cont : contacts) + for(AccountContactRelation cont : contacts.values()) { contactIdList.add(cont.ContactId); if(blaContactMap.containsKey(blaRecord)) { @@ -151,9 +151,13 @@ public with sharing class MassEmailController { LogService.logAndPublish(className, 'doSendRenewals', '', err); } } - public Static List getContacts(Id accountId, Id parentId){ - return [Select Id,ContactId,AccountId,IsActive,Contact.Email from AccountContactRelation where (AccountId = :accountId OR AccountId =: parentId) AND IsActive =true AND Contact.Email != NULL]; - + public Static Map getContacts(Id accountId, Id parentId){ + Map acrMap = new Map(); + List acrListcontacts = [Select Id,ContactId,AccountId,IsActive,Contact.Email from AccountContactRelation where (AccountId = :accountId OR AccountId =: parentId) AND IsActive =true AND Contact.Email != NULL]; + for(AccountContactRelation acr : acrListcontacts){ + acrMap.put(acr.ContactId, acr); + } + return acrMap; } //method to to send email to records-ALR-1000 @AuraEnabled @@ -164,7 +168,7 @@ public with sharing class MassEmailController { Id orgWideAddrId = NULL; Id blaRecord = NULL; Map> contactContentVerMap = new Map>(); - List contacts =new List(); + Map contacts = new Map(); try { //fetch acc status and rec type from metadata accDetails = BCMOH_UtilityClass.getAccRenewals(BCMOH_Constants.renewalName); @@ -223,7 +227,7 @@ public with sharing class MassEmailController { blaContactMap.put(blaRecord,new List()); } - for(AccountContactRelation cont : contacts) + for(AccountContactRelation cont : contacts.values()) { contactIdList.add(cont.ContactId); if(blaContactMap.containsKey(blaRecord)) { @@ -468,8 +472,9 @@ public with sharing class MassEmailController { try { if(sendEmailValid) { orgWideAddr = BCMOH_UtilityClass.getOrgWideEmailAddress(); - if(orgWideAddr != NULL) { + if(orgWideAddr != NULL) { orgWideAddrId = orgWideAddr.Id; + } else { errMessage = BCMOH_Constants.noOrgWideAddr; @@ -510,30 +515,31 @@ public with sharing class MassEmailController { //update bla success and error maps after sending email public static void getEmailStatus(Messaging.SendEmailResult[] emailResultList, List singleEmailMsgList, Map> whatIdTargetMap) { - Map, String> targetIdErrorMap = new Map, String>(); - try { - for(Messaging.SendEmailResult eResRec : emailResultList) { - if(!eResRec.isSuccess()) { - for(Messaging.SendEmailError err : eResRec.getErrors()) { - //targetIdErrorMap.put(err.getTargetObjectId(), err.getMessage()); - } - } - } - for(Messaging.SingleEmailMessage msgRec : singleEmailMsgList) { + Map, String> targetIdErrorMap = new Map, String>(); + try { + for(Messaging.SendEmailResult eResRec : emailResultList) { + if(!eResRec.isSuccess()) { + for(Messaging.SendEmailError err : eResRec.getErrors()) { + //targetIdErrorMap.put(err.getTargetObjectId(), err.getMessage()); + } + } + } + for(Messaging.SingleEmailMessage msgRec : singleEmailMsgList) { if(targetIdErrorMap.containsKey(whatIdTargetMap.get(msgRec.whatId))) { blaErrMap.put(msgRec.whatId, targetIdErrorMap.get(whatIdTargetMap.get(msgRec.whatId))); } else { String sentDetails = BCMOH_Constants.emailSentToId+' '+accContactMap.get(msgRec.whatId).Contact.Email+ '. '+BCMOH_Constants.emailSentTo+' '+accContactMap.get(msgRec.whatId).Contact.Name+'. '+BCMOH_Constants.sentTime+' '+datetime.now().format();//add to const - blaSuccessMap.put(msgRec.whatId, sentDetails); - } - } - } + blaSuccessMap.put(msgRec.whatId, sentDetails); + } + } + } catch(exception err) { - LogService.logAndPublish(className, 'updateTargetRecsStatus', '', err); - } - } + LogService.logAndPublish(className, 'updateTargetRecsStatus', '', err); + } +} + public static void updateBlaStatus() { Set blaIds = new Set(); diff --git a/src/main/default/classes/ScheduleSendEmail.cls b/src/main/default/classes/ScheduleSendEmail.cls index 1ffecb6d..c3e0bd18 100644 --- a/src/main/default/classes/ScheduleSendEmail.cls +++ b/src/main/default/classes/ScheduleSendEmail.cls @@ -7,7 +7,7 @@ public with sharing class ScheduleSendEmail implements Schedulable { - List contacts =new List(); + Map contacts = new Map(); public void execute(SchedulableContext sc) { List emails = new List(); @@ -29,7 +29,7 @@ public with sharing class ScheduleSendEmail implements Schedulable { Integer currentyear = Date.today().year(); Integer previousyear = Date.today().year() - 1; - for (AccountContactRelation acrList : contacts) { + for (AccountContactRelation acrList : contacts.values()) { if (acrList.contact.Email != null) { String key = acrList.AccountId + '_' + acrList.contact.Email.toLowerCase(); Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); @@ -58,8 +58,13 @@ public with sharing class ScheduleSendEmail implements Schedulable { } } - public Static List getContacts(Id accountId, Id parentId){ - return [Select Id,ContactId,AccountId,IsActive,Contact.Email from AccountContactRelation where (AccountId = :accountId OR AccountId =: parentId) AND IsActive =true AND Contact.Email != NULL]; + public Static Map getContacts(Id accountId, Id parentId){ + Map acrMap = new Map(); + List acrListcontacts = [Select Id,ContactId,AccountId,IsActive,Contact.Email from AccountContactRelation where (AccountId = :accountId OR AccountId =: parentId) AND IsActive =true AND Contact.Email != NULL]; + for(AccountContactRelation acr : acrListcontacts){ + acrMap.put(acr.ContactId, acr); + } + return acrMap; } diff --git a/src/main/default/classes/ScheduledEmailTrigger.cls b/src/main/default/classes/ScheduledEmailTrigger.cls index bade6aba..7daa5013 100644 --- a/src/main/default/classes/ScheduledEmailTrigger.cls +++ b/src/main/default/classes/ScheduledEmailTrigger.cls @@ -9,7 +9,7 @@ public with sharing class ScheduledEmailTrigger implements Schedulable { public Static Id emailTemplateId =NULL; public static Set accountIds = new Set(); Id blaRecord = NULL; - List contacts =new List(); + Map contacts = new Map(); Public Static Map> blaContactMap = new Map>(); Public Static List contactIdList = new List(); Public Static Map blaMap = new Map(); @@ -68,7 +68,7 @@ public with sharing class ScheduledEmailTrigger implements Schedulable { Boolean isValidAcc; Id blaRecord = NULL; Map templateIdEntityMap = new Map(); - List contacts =new List(); + Map contacts = new Map(); Map> accDetails = new Map>(); try { //fetch acc status and rec type from metadata @@ -128,7 +128,7 @@ public with sharing class ScheduledEmailTrigger implements Schedulable { blaContactMap.put(blaRecord,new List()); } - for(AccountContactRelation cont : contacts) + for(AccountContactRelation cont : contacts.values()) { contactIdList.add(cont.ContactId); if(blaContactMap.containsKey(blaRecord)) { @@ -165,9 +165,13 @@ public with sharing class ScheduledEmailTrigger implements Schedulable { } } - public Static List getContacts(Id accountId, Id parentId){ - return [Select Id,ContactId,AccountId,IsActive,Contact.Email from AccountContactRelation where (AccountId = :accountId OR AccountId =: parentId) AND IsActive =true AND Contact.Email != NULL]; - + public Static Map getContacts(Id accountId, Id parentId){ + Map acrMap = new Map(); + List acrListcontacts = [Select Id,ContactId,AccountId,IsActive,Contact.Email from AccountContactRelation where (AccountId = :accountId OR AccountId =: parentId) AND IsActive =true AND Contact.Email != NULL]; + for(AccountContactRelation acr : acrListcontacts){ + acrMap.put(acr.ContactId, acr); + } + return acrMap; } //send email method