Skip to content

Commit 6ac44f7

Browse files
committed
Release v6.0.0
1 parent f75de02 commit 6ac44f7

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

force-app/main/default/classes/main/cached-soql/SOQLCache_Test.cls

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,72 @@ private class SOQLCache_Test {
602602
@IsTest
603603
static void whereEqualStringField() {
604604
// Test
605-
Profile profile = (Profile) SOQLCache.of(Profile.SObjectType)
605+
// First query to cache the record
606+
Profile profile1 = (Profile) SOQLCache.of(Profile.SObjectType)
607+
.with(Profile.Id, Profile.Name)
608+
.whereEqual('Name', SYSTEM_ADMINISTRATOR)
609+
.toObject();
610+
611+
// Second query to retrieve the cached record
612+
Profile profile2 = (Profile) SOQLCache.of(Profile.SObjectType)
606613
.with(Profile.Id, Profile.Name)
607614
.whereEqual('Name', SYSTEM_ADMINISTRATOR)
608615
.toObject();
609616

610617
// Verify
611-
Assert.areEqual(SYSTEM_ADMINISTRATOR, profile.Name, 'The cached profile record should be "System Administrator".');
618+
Assert.areEqual(SYSTEM_ADMINISTRATOR, profile1.Name, 'The cached profile record should be "System Administrator".');
619+
Assert.areEqual(SYSTEM_ADMINISTRATOR, profile2.Name, 'The cached profile record should be "System Administrator".');
620+
Assert.areEqual(1, Limits.getQueries(), 'The number of queries should be 1.');
621+
}
622+
623+
@IsTest
624+
static void whereEqualIntegerField() {
625+
insertAccount();
626+
627+
// Test
628+
// First query to cache the record
629+
Account account1 = (Account) SOQLCache.of(Account.SObjectType)
630+
.with(Account.Id, Account.Name)
631+
.allowFilteringByNonUniqueFields()
632+
.whereEqual(Account.NumberOfEmployees, 1000)
633+
.toObject();
634+
635+
// Second query to retrieve the cached record
636+
Account account2 = (Account) SOQLCache.of(Account.SObjectType)
637+
.with(Account.Id, Account.Name)
638+
.allowFilteringByNonUniqueFields()
639+
.whereEqual(Account.NumberOfEmployees, 1000)
640+
.toObject();
641+
642+
// Verify
643+
Assert.areEqual(1000, account1.NumberOfEmployees, 'The cached account record should be 1000.');
644+
Assert.areEqual(1000, account2.NumberOfEmployees, 'The cached account record should be 1000.');
645+
Assert.areEqual(1, Limits.getQueries(), 'The number of queries should be 1.');
646+
}
647+
648+
@IsTest
649+
static void whereEqualBooleanField() {
650+
insertAccount();
651+
652+
// Test
653+
// First query to cache the record
654+
Account account1 = (Account) SOQLCache.of(Account.SObjectType)
655+
.with(Account.Id, Account.IsPartner)
656+
.allowFilteringByNonUniqueFields()
657+
.whereEqual(Account.IsPartner, FALSE)
658+
.toObject();
659+
660+
// Second query to retrieve the cached record
661+
Account account2 = (Account) SOQLCache.of(Account.SObjectType)
662+
.with(Account.Id, Account.IsPartner)
663+
.allowFilteringByNonUniqueFields()
664+
.whereEqual(Account.IsPartner, FALSE)
665+
.toObject();
666+
667+
// Verify
668+
Assert.areEqual(FALSE, account1.IsPartner, 'The cached account record should be FALSE.');
669+
Assert.areEqual(FALSE, account2.IsPartner, 'The cached account record should be FALSE.');
670+
Assert.areEqual(1, Limits.getQueries(), 'The number of queries should be 1.');
612671
}
613672

614673
@IsTest
@@ -1065,12 +1124,18 @@ private class SOQLCache_Test {
10651124
LastName = 'Testing',
10661125
LanguageLocaleKey = 'en_US',
10671126
LocaleSidKey = 'en_US',
1068-
ProfileId = [SELECT Id FROM Profile WHERE Name = 'Minimum Access - Salesforce'].Id,
1127+
Profile = new Profile(Name = 'Minimum Access - Salesforce'),
10691128
TimeZoneSidKey = 'America/Los_Angeles',
10701129
UserName = '[email protected]'
10711130
);
10721131
}
10731132

1133+
static Account insertAccount() {
1134+
Account account = new Account(Name = 'Test 1', NumberOfEmployees = 1000);
1135+
insert account;
1136+
return account;
1137+
}
1138+
10741139
public class SOQL_ProfileCache extends SOQLCache implements SOQLCache.Selector {
10751140
public SOQL_ProfileCache query() {
10761141
return new SOQL_ProfileCache();

0 commit comments

Comments
 (0)