Skip to content
Merged
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.project/
.nx-cache
.vscode/
.prettierrc

# Salesforce cache
.sf/
Expand Down
45 changes: 45 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"trailingComma": "none",
"arrowParens": "avoid",
"singleQuote": true,
"plugins": ["prettier-plugin-apex", "@prettier/plugin-xml"],
"overrides": [
{
"files": "**/lwc/**/*.html",
"options": {
"parser": "lwc",
"printWidth": 180
}
},
{
"files": "**/aura/**/*.cmp",
"options": {
"parser": "html",
"printWidth": 180,
"tabWidth": 4
}
},
{
"files": "*.{page,component}",
"options": {
"parser": "html",
"printWidth": 180
}
},
{
"files": "*.{cls,trigger,apex}",
"options": {
"parser": "apex",
"printWidth": 180,
"tabWidth": 4
}
},
{
"files": "*.{html,js,css}",
"options": {
"printWidth": 180,
"tabWidth": 4
}
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<a href="https://beyondthecloud.dev"><img alt="Beyond The Cloud logo" src="https://img.shields.io/badge/MADE_BY_BEYOND_THE_CLOUD-555?style=for-the-badge"></a>

<img alt="API version" src="https://img.shields.io/badge/api-v65.0-blue?style=for-the-badge">
<img alt="API version" src="https://img.shields.io/badge/api-v66.0-blue?style=for-the-badge">
<a href="https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-mit-green?style=for-the-badge"></a>
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/beyond-the-cloud-dev/soql-lib?style=for-the-badge&logo=github&color=blue">
<img alt="GitHub Release" src="https://img.shields.io/github/v/release/beyond-the-cloud-dev/soql-lib?display_name=tag&style=for-the-badge&color=blue">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
4 changes: 3 additions & 1 deletion force-app/main/default/classes/cached-soql/SOQLCache.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
*
* v6.7.0
* v6.8.0
*
* PMD False Positives:
* - ExcessivePublicCount: It is a library class and exposes all necessary methods to construct a query
Expand Down Expand Up @@ -277,10 +277,12 @@ global virtual inherited sharing class SOQLCache implements Cacheable {
}

global Id toId() {
this.with('Id');
return this.toObject()?.Id;
}

global Id toIdOf(SObjectField field) {
this.with(field);
return (Id) this.toObject()?.get(field);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
150 changes: 13 additions & 137 deletions force-app/main/default/classes/cached-soql/SOQLCache_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
*
* v6.7.0
* v6.8.0
*
* PMD False Positives:
* - CyclomaticComplexity: It is a library and we tried to put everything into ONE test class
* - CognitiveComplexity: It is a library and we tried to put everything into ONE class
**/
@SuppressWarnings('PMD.CyclomaticComplexity,PMD.CognitiveComplexity')
@IsTest
@IsTest(IsParallel=true)
private class SOQLCache_Test {
private static final String INITIAL_QUERY_MOCK_ID = 'cachedProfile';
private static final String SYSTEM_ADMINISTRATOR = 'System Administrator';
Expand Down Expand Up @@ -294,39 +294,6 @@ private class SOQLCache_Test {
Assert.areEqual(SYSTEM_ADMINISTRATOR, cachedProfile.Name, 'The cached profile record should be "System Administrator".');
}

@IsTest
static void allowQueryWithoutConditions() {
// Setup
insert new Account(Name = 'Test Account');

// Test
Account account = (Account) SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.allowQueryWithoutConditions()
.toObject();

// Verify
Assert.isNotNull(account, 'The account should be not null');
Assert.areEqual('Test Account', account.Name, 'The account name should be "Test Account"');
}

@IsTest
static void allowFilteringByNonUniqueFields() {
// Setup
insert new Account(Name = 'Test Account');

// Setup
Account account = (Account) SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.whereEqual(Account.Name, 'Test Account')
.allowFilteringByNonUniqueFields()
.toObject();

// Verify
Assert.isNotNull(account, 'The account should be not null');
Assert.areEqual('Test Account', account.Name, 'The account name should be "Test Account"');
}

@IsTest
static void listHasMoreThanOneRowForAssignmentToSObject() {
// Setup
Expand Down Expand Up @@ -620,56 +587,6 @@ private class SOQLCache_Test {
Assert.areEqual(1, Limits.getQueries(), 'The number of queries should be 1.');
}

@IsTest
static void whereEqualIntegerField() {
insertAccount();

// Test
// First query to cache the record
Account account1 = (Account) SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.allowFilteringByNonUniqueFields()
.whereEqual(Account.NumberOfEmployees, 1000)
.toObject();

// Second query to retrieve the cached record
Account account2 = (Account) SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.allowFilteringByNonUniqueFields()
.whereEqual(Account.NumberOfEmployees, 1000)
.toObject();

// Verify
Assert.areEqual(1000, account1.NumberOfEmployees, 'The cached account record should be 1000.');
Assert.areEqual(1000, account2.NumberOfEmployees, 'The cached account record should be 1000.');
Assert.areEqual(1, Limits.getQueries(), 'The number of queries should be 1.');
}

@IsTest
static void whereEqualBooleanField() {
insertAccount();

// Test
// First query to cache the record
Account account1 = (Account) SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.IsDeleted)
.allowFilteringByNonUniqueFields()
.whereEqual(Account.IsDeleted, false)
.toObject();

// Second query to retrieve the cached record
Account account2 = (Account) SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.IsDeleted)
.allowFilteringByNonUniqueFields()
.whereEqual(Account.IsDeleted, false)
.toObject();

// Verify
Assert.isFalse(account1.IsDeleted, 'The cached account record should be false.');
Assert.isFalse(account2.IsDeleted, 'The cached account record should be false.');
Assert.areEqual(1, Limits.getQueries(), 'The number of queries should be 1.');
}

@IsTest
static void whereEqualNotUniqueField() {
// Setup
Expand Down Expand Up @@ -729,38 +646,6 @@ private class SOQLCache_Test {
Assert.isNull(soqlException, 'An exception should not be thrown when more than one condition is introduced.');
}

@IsTest
static void stripInaccessible() {
// Setup
Task testTask = new Task(Subject = 'Test Task', Type = 'Other');
insert testTask;

System.runAs(minimumAccessUser()) {
// Test
Task cachedTask = (Task) SOQLCache.of(Task.SObjectType)
.with(Task.Id, Task.Type, Task.Subject)
.whereEqual(Task.Id, testTask.Id)
.stripInaccessible()
.toObject();

Exception queryException = null;
String inaccessibleFieldValue;

try {
inaccessibleFieldValue = cachedTask.Type;
} catch(Exception e) {
queryException = e;
}

// Verify
Assert.areEqual(
'SObject row was retrieved via SOQL without querying the requested field: Task.Type',
queryException.getMessage(),
'The stripInaccessible method should hide the inaccessible field value.'
);
}
}

@IsTest
static void mockId() {
// Setup
Expand Down Expand Up @@ -899,6 +784,17 @@ private class SOQLCache_Test {
Assert.isNotNull(systemAdministratorProfileId, 'The System Administrator profile Id must exist.');
}

@IsTest
static void toIdOfWhenFieldIsNotSet() {
// Test
Id createdById = SOQLCache.of(Profile.SObjectType)
.whereEqual(Profile.Name, SYSTEM_ADMINISTRATOR)
.toIdOf(Profile.CreatedById);

// Verify
Assert.isNotNull(createdById, 'The createdById should be null, even when not specified in the query.');
}

@IsTest
static void doExist() {
// Test
Expand Down Expand Up @@ -1165,26 +1061,6 @@ private class SOQLCache_Test {
Assert.areEqual('Random Profile Name', profile.Name, 'The profile name should be the same as the name assigned to the profile cache.');
}

static User minimumAccessUser() {
return new User(
Alias = 'newUser',
Email = 'newuser@testorg.com',
EmailEncodingKey = 'UTF-8',
LastName = 'Testing',
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
Profile = new Profile(Name = 'Minimum Access - Salesforce'),
TimeZoneSidKey = 'America/Los_Angeles',
Username = 'queryselector@testorg.com'
);
}

static Account insertAccount() {
Account account = new Account(Name = 'Test 1', NumberOfEmployees = 1000);
insert account;
return account;
}

public class SOQL_ProfileCache extends SOQLCache implements SOQLCache.Selector {
public SOQL_ProfileCache query() {
return new SOQL_ProfileCache();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
*
* v6.7.0
* v6.8.0
*
* PMD False Positives:
* - CognitiveComplexity: It is a library and we tried to put everything into ONE class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading