From 5b8f1ad23cf7b135a7051d02b8512e85fb9f82b4 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 10 Jan 2024 17:35:04 -0500 Subject: [PATCH 1/2] Remove sorting and filtering by the MailingState__c field allow it to support encrption --- force-app/test/ADDR_Addresses_TEST.cls | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/force-app/test/ADDR_Addresses_TEST.cls b/force-app/test/ADDR_Addresses_TEST.cls index b4a46dc426..088d667aa7 100644 --- a/force-app/test/ADDR_Addresses_TEST.cls +++ b/force-app/test/ADDR_Addresses_TEST.cls @@ -809,9 +809,12 @@ public with sharing class ADDR_Addresses_TEST { ); insert contact; - Address__c overrideAddress = [SELECT Undeliverable__c - FROM Address__c - WHERE MailingState__c = 'Pennsylvania']; + UTIL_Finder queryByState = new UTIL_Finder(Address__c.SObjectType) + .withSelectFields(new List{ 'Undeliverable__c' }) + .withWhere(new UTIL_Where.FieldExpression(Address__c.MailingState__c).equals('Pennsylvania')); + + + Address__c overrideAddress = (Address__c)(queryByState.find()[0]); Test.startTest(); overrideAddress.Undeliverable__c = true; @@ -2229,10 +2232,12 @@ public with sharing class ADDR_Addresses_TEST { insert testContact; Test.stopTest(); - Address__c testAddress = [SELECT Latest_Start_Date__c, Default_Address__c - FROM Address__c - WHERE MailingState__c = 'Washington' - LIMIT 1]; + UTIL_Finder queryByState = new UTIL_Finder(Address__c.SObjectType) + .withSelectFields(new List{ 'Latest_Start_Date__c', 'Default_Address__c' }) + .withWhere(new UTIL_Where.FieldExpression(Address__c.MailingState__c).equals('Washington')) + .withLimit(1); + + Address__c testAddress = (Address__c)(queryByState.find()[0]); System.assertEquals(true, testAddress.Default_Address__c, 'Address should be set as the default address.'); System.assertEquals(System.today(), testAddress.Latest_Start_Date__c, 'The default address latest start date ' + 'should be set to today\'s date.'); @@ -2548,7 +2553,6 @@ public with sharing class ADDR_Addresses_TEST { MailingStreet__c, MailingCity__c, MailingState__c, MailingPostalCode__c, MailingCountry__c FROM Address__c - ORDER BY MailingState__c ]; } From 802c1983fd2eb94814cad282453b363d69289554 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 12 Jan 2024 08:45:37 -0500 Subject: [PATCH 2/2] Remove use of UTIL_Finder because it appears when the field is encrypted, it's not available for SOSL fast enough for the test to work --- force-app/test/ADDR_Addresses_TEST.cls | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/force-app/test/ADDR_Addresses_TEST.cls b/force-app/test/ADDR_Addresses_TEST.cls index 088d667aa7..33e7d6edae 100644 --- a/force-app/test/ADDR_Addresses_TEST.cls +++ b/force-app/test/ADDR_Addresses_TEST.cls @@ -809,13 +809,14 @@ public with sharing class ADDR_Addresses_TEST { ); insert contact; - UTIL_Finder queryByState = new UTIL_Finder(Address__c.SObjectType) - .withSelectFields(new List{ 'Undeliverable__c' }) - .withWhere(new UTIL_Where.FieldExpression(Address__c.MailingState__c).equals('Pennsylvania')); - - - Address__c overrideAddress = (Address__c)(queryByState.find()[0]); - + Address__c overrideAddress; + for (Address__c addr : [SELECT Id, MailingState__c, Undeliverable__c FROM Address__c]) { + if (addr.MailingState__c == 'Pennsylvania') { + overrideAddress = addr; + break; + } + } + Test.startTest(); overrideAddress.Undeliverable__c = true; update overrideAddress; @@ -2232,12 +2233,14 @@ public with sharing class ADDR_Addresses_TEST { insert testContact; Test.stopTest(); - UTIL_Finder queryByState = new UTIL_Finder(Address__c.SObjectType) - .withSelectFields(new List{ 'Latest_Start_Date__c', 'Default_Address__c' }) - .withWhere(new UTIL_Where.FieldExpression(Address__c.MailingState__c).equals('Washington')) - .withLimit(1); + Address__c testAddress; + for (Address__c addr : [SELECT Id, MailingState__c, Latest_Start_Date__c, Default_Address__c FROM Address__c]) { + if (addr.MailingState__c == 'Washington') { + testAddress = addr; + break; + } + } - Address__c testAddress = (Address__c)(queryByState.find()[0]); System.assertEquals(true, testAddress.Default_Address__c, 'Address should be set as the default address.'); System.assertEquals(System.today(), testAddress.Latest_Start_Date__c, 'The default address latest start date ' + 'should be set to today\'s date.');