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-1162 #914

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 9 additions & 0 deletions src/main/default/classes/BCMOH_Constants.cls
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BCMOH_Constants {
public Final static String accountStat = 'Registered Active with Conditions';
public Final static String accStat= 'Registered Active Progressive Enforcement';
public Final static String accRecType= 'Residence';
public Final static String accRegType= 'Registrant';
public Final static String blaCompletedStatus= 'Completed';
//ALR-1000
public Final static String blaLateFeeStatus = 'Ready to Send';
Expand All @@ -55,11 +56,15 @@ public class BCMOH_Constants {
public Final static String templatePurpose = 'Renewal';
//error handling
public Final static String noPrimaryContact = 'No primary contact record or no email id on primary contact';
public Final static String noEmailFound = 'Invalid Email';
public Final static String noOrgWideAddr = 'No valid org wide email address found';
public Final static String noBLRec = 'No business license record found';
public Final static String mappingDataMissing = System.Label.TemplateFieldDataMissing;//'Data required for template merge field mapping is missing';
public Final static String templateNameMissing = 'No email template found for ';
public Final static String activePurposeTemplateMissing = 'No active email template name configured for ';
public Final static String noBusinessLicenseApplication = 'No Business License Application record';
public Final static String noBusinessLicense = 'No Business License record';
public Final static String noAssets = 'No Assets record';
//document error
public Final static String documentNotFound = 'Document not found for specified template name';
public Final static String nextYear = String.valueOf(Date.Today().Year() + 1);
Expand Down Expand Up @@ -87,6 +92,7 @@ public class BCMOH_Constants {
public Final static String regulatoryTransactionFee = 'Regulatory Transaction Fee';
public Final static String LatestContentVersionId = 'LatestContentVersionId';
public Final static String accountParent = 'Parent Account';

public Final static String accountParentAddr = 'Parent Account Billing Address';
public Final static String accountAddr = 'Account Address';
public Final static String relatedContacts = 'Related Contacts';
Expand Down Expand Up @@ -115,4 +121,7 @@ public class BCMOH_Constants {
public final static String TaskType = 'InspectionChecklist';
public final static String resultt = 'Non-compliant';
public final static String nulltest = 'null';
//ALR-192
public final static String orgDisplayName = 'ALR Support Email';
public final static String emailTemplate = 'UpcomingRenewalmailTemplate';
}
84 changes: 56 additions & 28 deletions src/main/default/classes/MassEmailController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public with sharing class MassEmailController {
//fetch acc status and rec type from metadata
accDetails = BCMOH_UtilityClass.getAccRenewals(BCMOH_Constants.renewalName);
for(Account activeAccRec : [SELECT Id, Status__c, Name,
(SELECT Id, ContactId, Contact.Name, Contact.Email, PrimaryContact__c
(SELECT Id, ContactId, Contact.Name, Contact.Email, PrimaryContact__c,IsActive
FROM AccountContactRelations
WHERE PrimaryContact__c = TRUE AND IsActive = TRUE AND Contact.Email != NULL LIMIT 1),
WHERE IsActive = TRUE AND Contact.Email != NULL),
(SELECT Id, Account.Name, RenewalYear__c, CreatedDate
FROM BusinessLicenseApplicationAccount
WHERE RecordType.DeveloperName =: BCMOH_Constants.blaRecType AND
Expand All @@ -72,9 +72,9 @@ public with sharing class MassEmailController {
WHERE RecordType.DeveloperName =: BCMOH_Constants.parentAssetRecType
AND Type__c IN: BCMOH_Constants.allALUnitTypes)
FROM Account
WHERE RecordType.DeveloperName =: accDetails.keyset() AND
WHERE (RecordType.DeveloperName =: BCMOH_Constants.accRecType OR RecordType.DeveloperName =: BCMOH_Constants.accRegType) AND
Status__c IN: accDetails.values()[0]
]) {
]){
isValidAcc = true;

if(activeAccRec.BusinessLicenseApplicationAccount.size() == 0) {
Expand Down Expand Up @@ -109,13 +109,21 @@ public with sharing class MassEmailController {
blaTotalAlUnitsMap.put(activeAccRec.BusinessLicenseApplicationAccount[0].Id, unitCounter);
}
//bla map and blaId-contactId map for email targetIds
for(BusinessLicenseApplication blaRec :
activeAccRec.BusinessLicenseApplicationAccount) {
blaMap.put(blaRec.Id, blaRec);
blaContactMap.put(blaRec.Id, activeAccRec.AccountContactRelations[0].ContactId);
}
for(BusinessLicenseApplication blaRec : activeAccRec.BusinessLicenseApplicationAccount) {
blaMap.put(blaRec.Id, blaRec);
List<Contact> contacts = getContacts(blaRec.AccountId);
for(Contact cont : contacts)
{
blaContactMap.put(blaRec.Id,cont.Id);

}
}

}
}
}



//if valid blas are fetched
if(!blaMap.isEmpty()) {
//fetch template Id
Expand All @@ -140,7 +148,9 @@ public with sharing class MassEmailController {
LogService.logAndPublish(className, 'doSendRenewals', '', err);
}
}

public Static List<Contact> getContacts(Id accountId){
return [Select id, Name from Contact where AccountId = :accountId];
}
//method to to send email to records-ALR-1000
@AuraEnabled
public static void doSendLateFee() {
Expand All @@ -153,9 +163,9 @@ public with sharing class MassEmailController {
//fetch acc status and rec type from metadata
accDetails = BCMOH_UtilityClass.getAccRenewals(BCMOH_Constants.renewalName);
for(Account activeAccRec : [SELECT Id, Status__c, Name,
(SELECT Id, ContactId, Contact.Name, Contact.Email, PrimaryContact__c
(SELECT Id, ContactId, Contact.Name, Contact.Email, PrimaryContact__c,IsActive
FROM AccountContactRelations
WHERE PrimaryContact__c = TRUE AND IsActive = TRUE AND Contact.Email != NULL LIMIT 1),
WHERE IsActive = TRUE AND Contact.Email != NULL),
(SELECT Id, Account.Name, RenewalYear__c, CreatedDate,AccountId
FROM BusinessLicenseApplicationAccount
WHERE RecordType.DeveloperName =: BCMOH_Constants.blaRecType AND
Expand All @@ -168,7 +178,7 @@ public with sharing class MassEmailController {
WHERE RecordType.DeveloperName =: BCMOH_Constants.parentAssetRecType
AND Type__c IN: BCMOH_Constants.allALUnitTypes)
FROM Account
WHERE RecordType.DeveloperName =: accDetails.keyset() AND
WHERE (RecordType.DeveloperName =: BCMOH_Constants.accRecType OR RecordType.DeveloperName =: BCMOH_Constants.accRegType) AND
Status__c IN: accDetails.values()[0]

]) {
Expand Down Expand Up @@ -202,11 +212,15 @@ public with sharing class MassEmailController {
}
blaTotalAlUnitsMap.put(activeAccRec.BusinessLicenseApplicationAccount[0].Id, unitCounter);
}
for(BusinessLicenseApplication blaRec :
activeAccRec.BusinessLicenseApplicationAccount) {
blaMap.put(blaRec.Id, blaRec);
blaContactMap.put(blaRec.Id, activeAccRec.AccountContactRelations[0].ContactId);
}
for(BusinessLicenseApplication blaRec : activeAccRec.BusinessLicenseApplicationAccount) {
blaMap.put(blaRec.Id, blaRec);
List<Contact> contacts = getContacts(blaRec.AccountId);
for(Contact cont : contacts)
{
blaContactMap.put(blaRec.Id,cont.Id);

}
}
}
}

Expand Down Expand Up @@ -241,11 +255,15 @@ public with sharing class MassEmailController {
Id contactId = NULL;
BusinessLicense blRec = new BusinessLicense();
Integer totalALUnits = 0;
List<Messaging.SingleEmailMessage> singleEmailMsgList = new List<Messaging.SingleEmailMessage>();
Id blaIdRec = NULL;
Set<Id> contId =New Set<Id>();

List<Id> attachIds = new List<Id>();
List<Messaging.SingleEmailMessage> singleEmailMsgList = new List<Messaging.SingleEmailMessage>();
try {
for(Id whatId : whatIdTargetMap.KeySet()) {
blaIdRec = whatId;
contactId = whatIdTargetMap.isEmpty() ? NULL : whatIdTargetMap.get(whatId);
List<Id> attachIds = new List<Id>(blaContentVerMap.get(whatId));
if(!blaMap.isEmpty() && !accMap.isEmpty() &&
blaMap.get(whatId) != NULL && accMap.get(whatId) != NULL) {
blRec = !blMap.isEmpty() && blMap.get(whatId) != NULL ? blMap.get(whatId) : NULL;//get BL record
Expand All @@ -263,24 +281,34 @@ public with sharing class MassEmailController {
if(subjectValue == NULL) {
continue;
}
if(!blaErrMap.containsKey(whatId)) {
Messaging.SingleEmailMessage emailMsgRec = BCMOH_UtilityClass.setEmailParams(contactId, NULL, orgWideAddrId, attachIds, whatId, emailBody, subjectValue, emailHtmlBody);//ALR-827 - added emailHtmlBody
singleEmailMsgList.add(emailMsgRec);

}

}
else {
blaErrMap.put(whatId, BCMOH_Constants.mappingDataMissing);//required data missing account and bla records-corner scenario
}
}

if(singleEmailMsgList != NULL && singleEmailMsgList.size() > 0) {
BusinessLicenseApplication blaObject= [select AccountId,Account.ParentId from BusinessLicenseApplication where Id=:blaIdRec LIMIT 1];

List<AccountContactRelation> conRec = [Select Id,AccountId,ContactId, Contact.Email,Account.ParentId from AccountContactRelation where (AccountId =: blaObject.AccountId OR AccountId =: blaObject.Account.ParentId) AND IsActive = TRUE];
for(AccountContactRelation acr : conRec){
contId.add(acr.ContactId);
}
for(AccountContactRelation conIds : conRec) {
if(!blaErrMap.containsKey(blaIdRec)) {
Messaging.SingleEmailMessage emailMsgRec = BCMOH_UtilityClass.setEmailParams(conIds.ContactId, NULL, orgWideAddrId, attachIds, blaIdRec, emailBody, subjectValue, emailHtmlBody);//ALR-827 - added emailHtmlBody
singleEmailMsgList.add(emailMsgRec);
}
}
if(singleEmailMsgList != NULL && singleEmailMsgList.size() > 0) {
Messaging.SendEmailResult[] emailResultList = Messaging.SendEmail(singleEmailMsgList, false);//send email inspite of failures in list
getEmailStatus(emailResultList, singleEmailMsgList, whatIdTargetMap);

}

}
catch(Exception err) {
system.debug('use exception handling sendEmailForRenewals'+err.getMessage());
system.debug('use exception handling sendEmailForRenewals'+err.getLineNumber());
}
}

Expand Down
Loading