From 61ebe00d1152bc8e609113038a0f12f4cd74e060 Mon Sep 17 00:00:00 2001 From: Daniel Fuller Date: Fri, 29 Apr 2022 14:55:18 -0400 Subject: [PATCH 1/4] add safe navigation operator when RollupFieldSet is null --- force-app/main/default/classes/RLLP_OppRollup_UTIL.cls | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/force-app/main/default/classes/RLLP_OppRollup_UTIL.cls b/force-app/main/default/classes/RLLP_OppRollup_UTIL.cls index 5a72b1b5b7..2102a86fbe 100644 --- a/force-app/main/default/classes/RLLP_OppRollup_UTIL.cls +++ b/force-app/main/default/classes/RLLP_OppRollup_UTIL.cls @@ -364,9 +364,10 @@ public without sharing class RLLP_OppRollup_UTIL { //iterate over objects provided to us for (sobject r : objectList){ //pull Id from rollup field and add to set - string[] rcf = ((string)(r.get('RollupFieldset'))).split(';\\|;',-4); - if(rcf.size() > 1 && rcf[1] != '') - opptysForCurrency.add((Id)rcf[4]); + List rollupFieldSet = ((String)(r.get('RollupFieldset')))?.split(';\\|;',-4); + if (rollupFieldSet?.size() > 1 && rollupFieldSet?.get(1) != '') { + opptysForCurrency.add((Id)rollupFieldSet[4]); + } } if (!objectlist.isEmpty()){ From 300473c9e6957519fe3b6efc22b1885dd7179ae8 Mon Sep 17 00:00:00 2001 From: Daniel Fuller Date: Mon, 2 May 2022 10:12:42 -0400 Subject: [PATCH 2/4] add unit test to cover --- .../default/classes/RLLP_OppRollup_TEST2.cls | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls b/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls index 5903297951..bcb51e6196 100644 --- a/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls +++ b/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls @@ -405,6 +405,9 @@ public with sharing class RLLP_OppRollup_TEST2 { npe01__Enable_Opportunity_Contact_Role_Trigger__c = true, npe01__Opportunity_Contact_Role_Default_role__c = CAO_Constants.OCR_DONOR_ROLE )); + UTIL_CustomSettingsFacade.getHouseholdsSettingsForTests(new npo02__Households_Settings__c( + npo02__Household_Rules__c = HH_Households.ALL_PROCESSOR + )); //exercise internal multicurrency helper methods, check currency conversion decimal d = UTIL_CurrencyConversion.convertFromCorporateUsingStandardRates('USD', 55.00); d = UTIL_CurrencyConversion.convertAmountUsingStandardRates('USD', 'USD', 55.00); @@ -439,6 +442,25 @@ public with sharing class RLLP_OppRollup_TEST2 { // UNDONE: THERE ARE NO ASSERTS!!!! } + + /********************************************************************************************************* + * @description For new Falcon instances, an aggregate query that returns no results is not returning an empty + * list but is returning a single record where the properties are null. This tests that scenario. + */ + @IsTest + static void getISOCodeWithNullRollupFieldSetDoesNotThrowException() { + List opportunitiesWithRollupFieldSets = [SELECT MAX(npo02__CombinedRollupFieldset__c) RollupFieldSet + FROM Opportunity + WHERE Id != NULL]; + Exception findCurrencyISOException; + try { + RLLP_OppRollup_UTIL.rcfFindCurrency(opportunitiesWithRollupFieldSets); + } catch (Exception ex) { + findCurrencyISOException = ex; + } + System.assertEquals(null, findCurrencyISOException, 'Retrieving the ISO codes for opportunities with define ' + + 'rollup field sets populated should not throw an exception when the rollup field set is null.'); + } /********************************************************************************************************* * @description Runs testRollupAlls test method for the One to One account processor. */ From c7eaa9fd90af420d06adb5c500e65c48b4eab9f5 Mon Sep 17 00:00:00 2001 From: Daniel Fuller Date: Mon, 2 May 2022 12:24:18 -0400 Subject: [PATCH 3/4] only execute test in multicurrency enabled org --- force-app/main/default/classes/RLLP_OppRollup_TEST2.cls | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls b/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls index bcb51e6196..a32c1a152b 100644 --- a/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls +++ b/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls @@ -449,6 +449,10 @@ public with sharing class RLLP_OppRollup_TEST2 { */ @IsTest static void getISOCodeWithNullRollupFieldSetDoesNotThrowException() { + if (!UTIL_Currency.getInstance().isMultiCurrencyOrganization()) { + return; + } + List opportunitiesWithRollupFieldSets = [SELECT MAX(npo02__CombinedRollupFieldset__c) RollupFieldSet FROM Opportunity WHERE Id != NULL]; From 046dde18f22a6f4718fbf1406ff132d47d1df97d Mon Sep 17 00:00:00 2001 From: Daniel Fuller Date: Mon, 2 May 2022 12:26:06 -0400 Subject: [PATCH 4/4] remove unused code line --- force-app/main/default/classes/RLLP_OppRollup_TEST2.cls | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls b/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls index a32c1a152b..c0db7dea76 100644 --- a/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls +++ b/force-app/main/default/classes/RLLP_OppRollup_TEST2.cls @@ -405,9 +405,7 @@ public with sharing class RLLP_OppRollup_TEST2 { npe01__Enable_Opportunity_Contact_Role_Trigger__c = true, npe01__Opportunity_Contact_Role_Default_role__c = CAO_Constants.OCR_DONOR_ROLE )); - UTIL_CustomSettingsFacade.getHouseholdsSettingsForTests(new npo02__Households_Settings__c( - npo02__Household_Rules__c = HH_Households.ALL_PROCESSOR - )); + //exercise internal multicurrency helper methods, check currency conversion decimal d = UTIL_CurrencyConversion.convertFromCorporateUsingStandardRates('USD', 55.00); d = UTIL_CurrencyConversion.convertAmountUsingStandardRates('USD', 'USD', 55.00);