diff --git a/src/main/default/classes/ChangeAccountOwner.cls b/src/main/default/classes/ChangeAccountOwner.cls index 18b4571a..d2a1d36b 100644 --- a/src/main/default/classes/ChangeAccountOwner.cls +++ b/src/main/default/classes/ChangeAccountOwner.cls @@ -34,24 +34,11 @@ public with sharing class ChangeAccountOwner { Id newOwnerId = input.newOwnerId; List accountId = input.accountId; - Boolean isBlaChecked = input.isBlaChecked; - Boolean isPublicChecked = input.isPublicChecked; - Boolean isCaseChecked = input.isCaseChecked; - Boolean isInspectionChecked = input.isInspectionChecked; - - if(isBlaChecked != null || isPublicChecked != null || isCaseChecked != null || isInspectionChecked != null){ - isBlaChecked = TRUE; - isPublicChecked = TRUE; - isCaseChecked = TRUE; - isInspectionChecked = TRUE; - } - else{ - isBlaChecked = FALSE; - isPublicChecked = FALSE; - isCaseChecked = FALSE; - isInspectionChecked = FALSE; - } - + Boolean isBlaChecked = input.isBlaChecked != null ? input.isBlaChecked : false; + Boolean isPublicChecked = input.isPublicChecked != null ? input.isPublicChecked : false; + Boolean isCaseChecked = input.isCaseChecked != null ? input.isCaseChecked : false; + Boolean isInspectionChecked = input.isInspectionChecked != null ? input.isInspectionChecked : false; + if (newOwnerId == null || accountId.isEmpty()) { return; } @@ -91,28 +78,28 @@ public with sharing class ChangeAccountOwner { Account acc = new Account(Id = accId.Id, OwnerId = newOwnerId); accountsToUpdate.add(acc); - if ((isBlaChecked && mapBlaRecords.containsKey(accId.Id)) || (accId.RecordType.DeveloperName != 'Registrant' && isBlaChecked == FALSE)) { + if ((isBlaChecked && mapBlaRecords.containsKey(accId.Id))) { for (BusinessLicenseApplication bla : mapBlaRecords.get(accId.Id)) { bla.OwnerId = newOwnerId; blaRecordsToUpdate.add(bla); } } - if ((isPublicChecked && mapPublicCompRecords.containsKey(accId.Id)) || (accId.RecordType.DeveloperName != 'Registrant' && isPublicChecked == FALSE)){ + if ((isPublicChecked && mapPublicCompRecords.containsKey(accId.Id))) { for (PublicComplaint pubComp : mapPublicCompRecords.get(accId.Id)) { pubComp.OwnerId = newOwnerId; publicCompRecordsToUpdate.add(pubComp); } } - if ((isCaseChecked && mapCaseRecords.containsKey(accId.Id)) || (accId.RecordType.DeveloperName != 'Registrant' && isCaseChecked == FALSE)) { + if ((isCaseChecked && mapCaseRecords.containsKey(accId.Id))) { for (Case caseRec : mapCaseRecords.get(accId.Id)) { caseRec.OwnerId = newOwnerId; caseRecordsToUpdate.add(caseRec); } } - if ((isInspectionChecked && mapVisitRecords.containsKey(accId.Id)) || (accId.RecordType.DeveloperName != 'Registrant' && isInspectionChecked == FALSE)) { + if ((isInspectionChecked && mapVisitRecords.containsKey(accId.Id))) { for (Visit visit : mapVisitRecords.get(accId.Id)) { visit.OwnerId = newOwnerId; visitRecordsToUpdate.add(visit); diff --git a/src/main/default/classes/FetchAndGenerateCSV.cls b/src/main/default/classes/FetchAndGenerateCSV.cls index a25cc1f4..782c3bf2 100644 --- a/src/main/default/classes/FetchAndGenerateCSV.cls +++ b/src/main/default/classes/FetchAndGenerateCSV.cls @@ -37,7 +37,7 @@ public with sharing class FetchAndGenerateCSV { List accounts = [SELECT Id, RegId__c, Name, HealthAuthority__c, ExemptionofAddressPublication__c, Phone, Extension__c, Fax, Website, Status__c, Parent.Name, (SELECT ContactId, PrimaryContact__c, Contact.Name FROM AccountContactRelations WHERE PrimaryContact__c = true LIMIT 1), (SELECT RegistrationCertificate__c FROM AccountBusinessLicenses__r WHERE Status = 'Active' LIMIT 1), - (SELECT ServiceName__c FROM Services__r WHERE ServiceName__c IN: serviceNameList LIMIT 50), + (SELECT ServiceName__c, Status__c FROM Services__r WHERE ServiceName__c IN: serviceNameList LIMIT 50), (SELECT Id, Location.VisitorAddress.Address FROM AssociatedLocations WHERE ActiveTo = NULL LIMIT 1), Account.LicenseType__r.RegulatoryAuthorizationCode__c, (SELECT Quantity, Type__c FROM Assets WHERE Type__c IN: typeList AND ParentId = NULL AND Quantity > 0.00) @@ -140,7 +140,7 @@ public with sharing class FetchAndGenerateCSV { // Helper method to get the service flag private static String getServiceFlag(List services, String serviceName){ for(Service__c service : services){ - if(!String.isEmpty(serviceName) && serviceName.containsIgnoreCase(service.ServiceName__c)){ + if(service.Status__c == 'Active' && service.ServiceName__c == serviceName){ return '-1'; // Flag '-1' if service name is found } } diff --git a/src/main/default/classes/FetchAndGenerateCSVTest.cls b/src/main/default/classes/FetchAndGenerateCSVTest.cls index b800629d..1fc25a9f 100644 --- a/src/main/default/classes/FetchAndGenerateCSVTest.cls +++ b/src/main/default/classes/FetchAndGenerateCSVTest.cls @@ -60,6 +60,7 @@ private class FetchAndGenerateCSVTest { ServiceName__c = 'Assistance with daily living activities', ServiceType__c = 'Assisted Living Service', ProvidedBy__c = 'Registrant', + Status__c = 'Active', Account__c = Residence.id ); insert ser; @@ -122,6 +123,7 @@ private class FetchAndGenerateCSVTest { ServiceName__c = 'Assistance with daily living activities', ServiceType__c = 'Assisted Living Service', ProvidedBy__c = 'Registrant', + Status__c = 'Active', Account__c = Residence.id ); insert ser;