Skip to content

Commit 61de0e6

Browse files
authored
Release/v5.0.0 (#157)
* Mocking improvements [DRAFT] (#154) * draft Signed-off-by: Piotr PG Gajek <[email protected]> * draft Signed-off-by: Piotr PG Gajek <[email protected]> * stripAdditionalFields Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * performance improvement Signed-off-by: Piotr PG Gajek <[email protected]> * refactor Signed-off-by: Piotr PG Gajek <[email protected]> * performance update Signed-off-by: Piotr PG Gajek <[email protected]> * Refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * documentation update Signed-off-by: Piotr PG Gajek <[email protected]> * documentation Signed-off-by: Piotr PG Gajek <[email protected]> * main page Signed-off-by: Piotr PG Gajek <[email protected]> * logo Signed-off-by: Piotr PG Gajek <[email protected]> * documentation improvement Signed-off-by: Piotr PG Gajek <[email protected]> * documentation Signed-off-by: Piotr PG Gajek <[email protected]> * fix Signed-off-by: Piotr PG Gajek <[email protected]> --------- Signed-off-by: Piotr PG Gajek <[email protected]> * documentation Signed-off-by: Piotr PG Gajek <[email protected]> * debugging Signed-off-by: Piotr PG Gajek <[email protected]> * documentation Signed-off-by: Piotr PG Gajek <[email protected]> * mocking Signed-off-by: Piotr PG Gajek <[email protected]> * mocking Signed-off-by: Piotr PG Gajek <[email protected]> * documentation Signed-off-by: Piotr PG Gajek <[email protected]> * main page Signed-off-by: Piotr PG Gajek <[email protected]> * result Signed-off-by: Piotr PG Gajek <[email protected]> --------- Signed-off-by: Piotr PG Gajek <[email protected]>
1 parent 5c295aa commit 61de0e6

File tree

3 files changed

+154
-53
lines changed

3 files changed

+154
-53
lines changed

website/docs/examples/standard-soql/result.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ Id accountId = SOQL.of(Account.SObjectType).setLimit(1).toId();
2727
**Apex**
2828

2929
```apex
30+
Integer accountsWithMoreThan100Employees = [
31+
SELECT COUNT()
32+
FROM Account
33+
WHERE NumberOfEmployees > 100
34+
];
3035
36+
Boolean hasAccountsWithMoreThan100Employees = accountsWithMoreThan100Employees > 0;
3137
```
3238

3339
**SOQL Lib**
3440

3541
```apex
42+
Boolean hasAccountsWithMoreThan100Employees = SOQL.of(Account.SObjectType)
43+
.whereAre(SOQL.Filter(Account.NumberOfEmployees).greaterThan(100))
44+
.doExist();
3645
```
3746

3847
## toValueOf

website/src/pages/index.js

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
11
import Layout from '@theme/Layout';
22
import Heading from '@theme/Heading';
3-
4-
const FEATURES = [
5-
{
6-
title: 'Lightweight Selector Classes',
7-
description: 'Keep your selector classes minimal, focusing only on essential query configurations (fields, sharing settings) and generic methods (byId, byRecordType).',
8-
image: '/img/small-selectors.png'
9-
},
10-
{
11-
title: 'Build SOQL Inline with a Query Builder',
12-
description: 'Most queries are business-specific. Define them exactly where they’re needed using SOQL Lib’s builder, keeping the Selector class for only generic or reusable queries.',
13-
image: '/img/build-inline.png'
14-
},
15-
{
16-
title: 'Full Control of FLS and Sharing',
17-
description: 'Easily enforce Field-Level Security and sharing rules using .systemMode(), .withSharing(), or .withoutSharing().',
18-
image: '/img/fls-and-sharing-settings.png'
19-
},
20-
{
21-
title: 'Mock SOQL for Faster Tests',
22-
description: 'Boost unit test performance by mocking SOQL results, reducing the need for complex test data setups.',
23-
image: '/img/mocking.png'
24-
},
25-
{
26-
title: 'Accelerate Performance with Cached Selectors',
27-
description: 'Store records in Apex transactions, Org Cache, or Session Cache, minimizing redundant queries for faster performance.',
28-
image: '/img/cached-selector.png'
29-
},
30-
{
31-
title: 'Enhanced SOQL Toolkit',
32-
description: 'Leverage a suite of predefined methods to simplify query results and reduce code complexity.',
33-
image: '/img/enhanced-soql.png'
34-
}
35-
];
3+
import MDXContent from '@theme/MDXContent';
4+
import SOQLLibBenefits from './soqlLibBenefits.mdx';
365

376
export default function Home() {
387
return (
@@ -52,26 +21,8 @@ export default function Home() {
5221

5322
export function Features() {
5423
return (
55-
<div className='my-10 flex flex-col max-w-5xl mx-auto gap-10'>
56-
{
57-
FEATURES.map(feature => (
58-
<div class="flex px-10 lg:px-0 gap-10 flex-col items-center lg:flex-row lg:items-start lg:justify-between">
59-
<div class="max-w-2xl text-justify">
60-
<Heading as="h2">
61-
{feature.title}
62-
</Heading>
63-
<div>{feature.description}</div>
64-
</div>
65-
66-
<img
67-
src={feature.image}
68-
alt={feature.title}
69-
width="60%"
70-
class="shadow-sm"
71-
/></div>
72-
73-
))
74-
}
24+
<div className='my-10 flex flex-col max-w-5xl mx-auto'>
25+
<MDXContent><SOQLLibBenefits /></MDXContent>
7526
</div>
7627
)
7728
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
## Lightweight Selector Classes
2+
3+
Keep your selector classes minimal, focusing only on essential query configurations (fields, sharing settings) and generic methods (byId, byRecordType). All other queries can be built inline using the SOQL Lib builder.
4+
5+
```apex
6+
public inherited sharing class SOQL_Contact extends SOQL implements SOQL.Selector {
7+
public static SOQL_Contact query() {
8+
return new SOQL_Contact();
9+
}
10+
11+
private SOQL_Contact() {
12+
super(Contact.SObjectType);
13+
// default settings
14+
with(Contact.Id, Contact.Name, Contact.AccountId)
15+
.systemMode()
16+
.withoutSharing();
17+
}
18+
19+
public SOQL_Contact byAccountId(Id accountId) {
20+
whereAre(Filter.with(Contact.AccountId).equal(accountId));
21+
return this;
22+
}
23+
24+
public SOQL_Contact bySource(String source) {
25+
whereAre(Filter.with(Contact.ContactSource).equal(source));
26+
return this;
27+
}
28+
}
29+
```
30+
31+
## Build SOQL Inline with a Query Builder
32+
33+
Most queries are business-specific. Define them exactly where they’re needed using SOQL Lib’s builder, keeping the Selector class for only generic or reusable queries. Pull only the necessary fields.
34+
35+
```apex
36+
public with sharing class ExampleController {
37+
@AuraEnabled
38+
public static List<Contact> getAccountContacts(Id accountId) {
39+
return SOQL_Contact.query()
40+
.byAccountId(accountId)
41+
.bySource('Website')
42+
.with(Contact.Email, Contact.Department)
43+
.setLimit(100)
44+
.toList();
45+
}
46+
}
47+
```
48+
49+
## Full Control of FLS and Sharing
50+
51+
Easily enforce Field-Level Security and sharing rules using .systemMode(), .withSharing(), or .withoutSharing().
52+
53+
```apex
54+
public inherited sharing class SOQL_Contact extends SOQL implements SOQL.Selector {
55+
public static SOQL_Contact query() {
56+
return new SOQL_Contact();
57+
}
58+
59+
private SOQL_Contact() {
60+
super(Contact.SObjectType);
61+
// default settings
62+
with(Contact.Id, Contact.Name, Contact.AccountId);
63+
// FLS
64+
systemMode();
65+
// Sharing Mode
66+
withoutSharing();
67+
}
68+
}
69+
```
70+
71+
## Mock SOQL for Faster Tests
72+
73+
Boost unit test performance by mocking SOQL results, reducing the need for complex test data setups.
74+
75+
```apex
76+
List<Account> accounts = new List<Account>{
77+
new Account(Name = 'MyAccount 1'),
78+
new Account(Name = 'MyAccount 2')
79+
};
80+
81+
SOQL.mock('ExampleController.getPartnerAccounts')
82+
.thenReturn(accounts);
83+
84+
Test.startTest();
85+
List<Account> result = ExampleController.getPartnerAccounts('MyAccount');
86+
Test.stopTest();
87+
88+
// Assert
89+
```
90+
91+
## Accelerate Performance with Cached Selectors
92+
93+
Store records in Apex transactions, Org Cache, or Session Cache, minimizing redundant queries for faster performance.
94+
95+
```apex
96+
public with sharing class SOQL_ProfileCache extends SOQLCache implements SOQLCache.Selector {
97+
public static SOQL_ProfileCache query() {
98+
return new SOQL_ProfileCache();
99+
}
100+
101+
private SOQL_ProfileCache() {
102+
super(Profile.SObjectType);
103+
cacheInOrgCache();
104+
maxHoursWithoutRefresh(48);
105+
with(Profile.Id, Profile.Name, Profile.UserType);
106+
}
107+
108+
public override SOQL.Queryable initialQuery() {
109+
return SOQL.of(Profile.SObjectType);
110+
}
111+
112+
public SOQL_ProfileCache byName(String name) {
113+
whereEqual(Profile.Name, name);
114+
return this;
115+
}
116+
}
117+
```
118+
119+
## Enhanced SOQL Toolkit
120+
121+
Leverage a suite of predefined methods to simplify query results and reduce code complexity.
122+
123+
```apex
124+
Id toId();
125+
Boolean doExist();
126+
String toString();
127+
Object toValueOf(SObjectField fieldToExtract);
128+
Set<String> toValuesOf(SObjectField fieldToExtract);
129+
Integer toInteger();
130+
SObject toObject();
131+
List<SObject> toList();
132+
List<AggregateResult> toAggregated();
133+
Map<Id, SObject> toMap();
134+
Map<String, SObject> toMap(SObjectField keyField);
135+
Map<String, SObject> toMap(String relationshipName, SObjectField targetKeyField);
136+
Map<String, String> toMap(SObjectField keyField, SObjectField valueField);
137+
Map<String, List<SObject>> toAggregatedMap(SObjectField keyField);
138+
Map<String, List<SObject>> toAggregatedMap(String relationshipName, SObjectField targetKeyField);
139+
Map<String, List<String>> toAggregatedMap(SObjectField keyField, SObjectField valueField);
140+
Database.QueryLocator toQueryLocator();
141+
```

0 commit comments

Comments
 (0)