Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALR - 1839 #1025

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions src/main/default/classes/MassEmailController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public with sharing class MassEmailController {
Id orgWideAddrId = NULL;
Id blaRecord = NULL;
Map<Id, Set<Id>> contactContentVerMap = new Map<Id, Set<Id>>();
List<AccountContactRelation> contacts =new List<AccountContactRelation>();
Map<Id, AccountContactRelation> contacts = new Map<Id, AccountContactRelation>();

try {
//fetch acc status and rec type from metadata
Expand Down Expand Up @@ -114,7 +114,7 @@ public with sharing class MassEmailController {

blaContactMap.put(blaRecord,new List<Id>());
}
for(AccountContactRelation cont : contacts)
for(AccountContactRelation cont : contacts.values())
{
contactIdList.add(cont.ContactId);
if(blaContactMap.containsKey(blaRecord)) {
Expand Down Expand Up @@ -151,9 +151,13 @@ public with sharing class MassEmailController {
LogService.logAndPublish(className, 'doSendRenewals', '', err);
}
}
public Static List<AccountContactRelation> 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<Id, AccountContactRelation> getContacts(Id accountId, Id parentId){
Map<Id, AccountContactRelation> acrMap = new Map<Id, AccountContactRelation>();
List<AccountContactRelation> 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
Expand All @@ -164,7 +168,7 @@ public with sharing class MassEmailController {
Id orgWideAddrId = NULL;
Id blaRecord = NULL;
Map<Id, Set<Id>> contactContentVerMap = new Map<Id, Set<Id>>();
List<AccountContactRelation> contacts =new List<AccountContactRelation>();
Map<Id, AccountContactRelation> contacts = new Map<Id, AccountContactRelation>();
try {
//fetch acc status and rec type from metadata
accDetails = BCMOH_UtilityClass.getAccRenewals(BCMOH_Constants.renewalName);
Expand Down Expand Up @@ -223,7 +227,7 @@ public with sharing class MassEmailController {

blaContactMap.put(blaRecord,new List<Id>());
}
for(AccountContactRelation cont : contacts)
for(AccountContactRelation cont : contacts.values())
{
contactIdList.add(cont.ContactId);
if(blaContactMap.containsKey(blaRecord)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Messaging.SingleEmailMessage> singleEmailMsgList, Map<Id, List<Id>> whatIdTargetMap) {
Map<List<Id>, String> targetIdErrorMap = new Map<List<Id>, 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<List<Id>, String> targetIdErrorMap = new Map<List<Id>, 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<Id> blaIds = new Set<Id>();
Expand Down
13 changes: 9 additions & 4 deletions src/main/default/classes/ScheduleSendEmail.cls
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public with sharing class ScheduleSendEmail implements Schedulable {

List<AccountContactRelation> contacts =new List<AccountContactRelation>();
Map<Id, AccountContactRelation> contacts = new Map<Id, AccountContactRelation>();

public void execute(SchedulableContext sc) {
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
Expand All @@ -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();
Expand Down Expand Up @@ -58,8 +58,13 @@ public with sharing class ScheduleSendEmail implements Schedulable {
}
}

public Static List<AccountContactRelation> 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<Id, AccountContactRelation> getContacts(Id accountId, Id parentId){
Map<Id, AccountContactRelation> acrMap = new Map<Id, AccountContactRelation>();
List<AccountContactRelation> 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;
}


Expand Down
16 changes: 10 additions & 6 deletions src/main/default/classes/ScheduledEmailTrigger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public with sharing class ScheduledEmailTrigger implements Schedulable {
public Static Id emailTemplateId =NULL;
public static Set<Id> accountIds = new Set<Id>();
Id blaRecord = NULL;
List<AccountContactRelation> contacts =new List<AccountContactRelation>();
Map<Id, AccountContactRelation> contacts = new Map<Id, AccountContactRelation>();
Public Static Map<Id, List<Id>> blaContactMap = new Map<Id, List<Id>>();
Public Static List<Id> contactIdList = new List<Id>();
Public Static Map<Id, BusinessLicenseApplication> blaMap = new Map<Id, BusinessLicenseApplication>();
Expand Down Expand Up @@ -68,7 +68,7 @@ public with sharing class ScheduledEmailTrigger implements Schedulable {
Boolean isValidAcc;
Id blaRecord = NULL;
Map<Id, String> templateIdEntityMap = new Map<Id, String>();
List<AccountContactRelation> contacts =new List<AccountContactRelation>();
Map<Id, AccountContactRelation> contacts = new Map<Id, AccountContactRelation>();
Map<String, List<String>> accDetails = new Map<String, List<String>>();
try {
//fetch acc status and rec type from metadata
Expand Down Expand Up @@ -128,7 +128,7 @@ public with sharing class ScheduledEmailTrigger implements Schedulable {

blaContactMap.put(blaRecord,new List<Id>());
}
for(AccountContactRelation cont : contacts)
for(AccountContactRelation cont : contacts.values())
{
contactIdList.add(cont.ContactId);
if(blaContactMap.containsKey(blaRecord)) {
Expand Down Expand Up @@ -165,9 +165,13 @@ public with sharing class ScheduledEmailTrigger implements Schedulable {
}
}

public Static List<AccountContactRelation> 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<Id, AccountContactRelation> getContacts(Id accountId, Id parentId){
Map<Id, AccountContactRelation> acrMap = new Map<Id, AccountContactRelation>();
List<AccountContactRelation> 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
Expand Down