Skip to content

Commit 22a702b

Browse files
committed
Merge branch 'main' of https://github.com/beyond-the-cloud-dev/soql-lib into release/v5.2.0
2 parents 1eaf019 + 28d9455 commit 22a702b

File tree

16 files changed

+366
-39
lines changed

16 files changed

+366
-39
lines changed

website/docs/advanced-usage/fls.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ none (by default) | `USER_MODE` | enforced
1616

1717
## Default
1818

19-
`USER_MODE` is a enabled by default. It means that **the object permissions, field-level security**, as well as sharing rules, **are enforced**.
19+
`USER_MODE` is enabled by default. It means that **the object permissions, field-level security**, as well as sharing rules, **are enforced**.
2020

2121
```apex title="SOQL_Account.cls"
2222
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
@@ -46,7 +46,7 @@ public without sharing class ExampleController {
4646

4747
### System Mode
4848

49-
Developer can disable `USER_MODE` and enable `SYSTEM_MODE` using `.systemMode()` method.
49+
Developers can disable `USER_MODE` and enable `SYSTEM_MODE` using the `.systemMode()` method.
5050

5151
```apex title="SOQL_Account.cls"
5252
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
sidebar_position: 40
3+
---
4+
5+
# Known Issues
6+
7+
## Variable does not exist
8+
9+
Error: `System.QueryException: Variable does not exist: v1`
10+
11+
### Root Cause
12+
13+
This is **NOT** the lib issue but rather a Salesforce platform limitation that occurs when `Database.getQueryLocatorWithBinds` is used with insufficient permissions.
14+
15+
This error occurs when all of the following conditions are met:
16+
- `toQueryLocator()` is executed
17+
- Query is executed with `USER_MODE` (which is the default mode if not otherwise specified)
18+
- Query contains fields to which the user doesn't have access
19+
- Query has at least one condition, which means that a binding map is used
20+
21+
**Example that fails:**
22+
23+
**Apex**
24+
25+
```apex
26+
Database.getQueryLocatorWithBinds(
27+
'SELECT Type FROM Task WHERE Type != :v1',
28+
new Map<String, Object>{'v1' => null},
29+
AccessLevel.USER_MODE
30+
);
31+
```
32+
33+
**SOQL Lib**
34+
35+
```apex
36+
SOQL.of(Task.SObjectType)
37+
.with(Task.Type) // <== no access to this field
38+
.whereAre(SOQL.Filter.with(Task.Type).isNotNull())
39+
.toQueryLocator();
40+
```
41+
42+
### Solutions
43+
44+
#### Ensure user has field access permissions
45+
46+
Grant the user appropriate field-level security permissions for the fields used in the query.
47+
48+
#### Use SYSTEM_MODE
49+
50+
**Apex**
51+
```apex
52+
Database.getQueryLocatorWithBinds(
53+
'SELECT Type FROM Task WHERE Type != :v1',
54+
new Map<String, Object>{'v1' => null},
55+
AccessLevel.SYSTEM_MODE
56+
);
57+
```
58+
59+
**SOQL Lib**
60+
61+
```apex
62+
SOQL.of(Task.SObjectType)
63+
.with(Task.Type)
64+
.whereAre(SOQL.Filter.with(Task.Type).isNotNull())
65+
.systemMode()
66+
.toQueryLocator();
67+
```

website/docs/advanced-usage/mocking.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ sidebar_position: 30
44

55
# Mocking
66

7-
Mocking provides a way to substitute records from a Database with some prepared data. Data can be prepared in form of SObject records and lists in Apex code or Static Resource `.csv` file.
8-
Mocked queries won't make any SOQL's and simply return data set in method definition, mock __will ignore all filters and relations__, what is returned depends __solely on data provided to the method__. Mocking is working __only during test execution__. To mock SOQL query, use `.mockId(id)` method to make it identifiable. If you mark more than one query with the same ID, all marked queries will return the same data.
7+
Mocking provides a way to substitute records from a database with some prepared data. Data can be prepared in the form of SObject records and lists in Apex code or Static Resource `.csv` file.
8+
Mocked queries won't make any SOQLs and simply return data set in method definition, mock __will ignore all filters and relations__, what is returned depends __solely on data provided to the method__. Mocking is working __only during test execution__. To mock SOQL query, use `.mockId(id)` method to make it identifiable. If you mark more than one query with the same ID, all marked queries will return the same data.
99

1010
```apex title="ExampleController.cls"
1111
public with sharing class ExampleController {
@@ -23,7 +23,7 @@ public with sharing class ExampleController {
2323
}
2424
```
2525

26-
Then in test simply pass data you want to get from Selector to `SOQL.mock(id).thenReturn(data)` method. Acceptable formats are: `List<SObject>` or `SObject`. Then during execution Selector will return desired data.
26+
Then in tests simply pass data you want to get from Selector to `SOQL.mock(id).thenReturn(data)` method. Acceptable formats are: `List<SObject>` or `SObject`. Then during execution Selector will return the desired data.
2727

2828
## Insights
2929

website/docs/advanced-usage/sharing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ none (by default) | `USER_MODE` | `with sharing`
1717

1818
## Default
1919

20-
`USER_MODE` is a enabled by default. It means that the object permissions, field-level security and **sharing rules are enforced**.
20+
`USER_MODE` is enabled by default. It means that the object permissions, field-level security and **sharing rules are enforced**.
2121

2222
```apex title="SOQL_Account.cls"
2323
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {

website/docs/api/standard-soql/soql-join.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The following are methods for `FilterGroup`.
3434
## INIT
3535
### of
3636

37-
Conctructs an `JoinQuery`.
37+
Constructs a `JoinQuery`.
3838

3939
**Signature**
4040

website/docs/api/standard-soql/soql-sub.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The following are methods for `SubQuery`.
6767
## INIT
6868
### of
6969

70-
Conctructs an `SubQuery`.
70+
Constructs a `SubQuery`.
7171

7272
**Signature**
7373

website/docs/api/standard-soql/soql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ The following are methods for using `SOQL`:
211211
## INIT
212212
### of
213213

214-
Conctructs an `SOQL`.
214+
Constructs an `SOQL`.
215215

216216
**Signature**
217217

website/docs/docs/basic-features.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ By default, all queries are executed `with sharing`, enforced by `AccessLevel.US
8484

8585
`AccessLevel.USER_MODE` enforces object permissions and field-level security.
8686

87-
Developer can skip FLS by adding `.systemMode()` and `.withSharing()`.
87+
Developers can skip FLS by adding `.systemMode()` and `.withSharing()`.
8888

8989
```apex
9090
// Query executed in without sharing
@@ -97,7 +97,7 @@ SOQL.of(Account.SObjectType)
9797

9898
### without sharing
9999

100-
Developer can control sharing rules by adding `.systemMode()` (record sharing rules are controlled by the sharingMode) and `.withoutSharing()`.
100+
Developers can control sharing rules by adding `.systemMode()` (record sharing rules are controlled by the sharingMode) and `.withoutSharing()`.
101101

102102
```apex
103103
// Query executed in with sharing
@@ -110,7 +110,7 @@ SOQL.of(Account.SObjectType)
110110

111111
### inherited sharing
112112

113-
Developer can control sharing rules by adding `.systemMode()` (record sharing rules are controlled by the sharingMode) by default it is `inherited sharing`.
113+
Developers can control sharing rules by adding `.systemMode()` (record sharing rules are controlled by the sharingMode); by default it is `inherited sharing`.
114114

115115
```apex
116116
// Query executed in inherited sharing
@@ -204,7 +204,7 @@ private class ExampleControllerTest {
204204

205205
### Count Result
206206

207-
```
207+
```apex
208208
@IsTest
209209
private class ExampleControllerTest {
210210
@@ -219,9 +219,39 @@ private class ExampleControllerTest {
219219
}
220220
```
221221

222+
### Aggregate Result
223+
224+
```apex
225+
@IsTest
226+
private class ExampleControllerTest {
227+
228+
@IsTest
229+
static void getLeadSourceCounts() {
230+
List<Map<String, Object>> aggregateResults = new List<Map<String, Object>>{
231+
new Map<String, Object>{ 'LeadSource' => 'Web', 'total' => 10},
232+
new Map<String, Object>{ 'LeadSource' => 'Phone', 'total' => 5},
233+
new Map<String, Object>{ 'LeadSource' => 'Email', 'total' => 3}
234+
};
235+
236+
SOQL.mock('mockingQuery').thenReturn(aggregateResults);
237+
238+
List<SOQL.AggregateResultProxy> result = SOQL.of(Lead.SObjectType)
239+
.with(Lead.LeadSource)
240+
.count(Lead.Id, 'total')
241+
.groupBy(Lead.LeadSource)
242+
.mockId('mockingQuery')
243+
.toAggregatedProxy();
244+
245+
Assert.areEqual(3, result.size());
246+
Assert.areEqual(10, result[0].get('total'));
247+
Assert.areEqual('Web', result[0].get('LeadSource'));
248+
}
249+
}
250+
```
251+
222252
## Avoid duplicates
223253

224-
Generic SOQLs can be keep in selector class.
254+
Generic SOQLs can be kept in the selector class.
225255

226256
```apex
227257
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
@@ -325,7 +355,7 @@ Did you know that?
325355
- Retrieving data from the cache takes less than 10ms.
326356
- Read operations (SOQL) account for approximately 70% of an org’s activity.
327357

328-
Cache can significantly boost yours orgs performance. You can it use for objects like:
358+
Cache can significantly boost your org's performance. You can use it for objects like:
329359

330360
- `Profile`
331361
- `BusinessHours`
@@ -358,21 +388,26 @@ public with sharing class SOQL_ProfileCache extends SOQLCache implements SOQLCac
358388
}
359389
```
360390

361-
## Enchanced SOQL
391+
## Enhanced SOQL
362392

363-
Developers perform different SOQL results transformation.
364-
You can use many of predefined method that will reduce your code complexity.
393+
Developers perform different SOQL result transformations.
394+
You can use many predefined methods that will reduce your code complexity.
365395

366396
```apex
367397
Id toId();
398+
Set<Id> toIds();
399+
Set<Id> toIdsOf(SObjectField field);
400+
Set<Id> toIdsOf(String relationshipName, SObjectField field);
368401
Boolean doExist();
369402
String toString();
370403
Object toValueOf(SObjectField fieldToExtract);
371404
Set<String> toValuesOf(SObjectField fieldToExtract);
405+
Set<String> toValuesOf(String relationshipName, SObjectField targetKeyField);
372406
Integer toInteger();
373407
SObject toObject();
374408
List<SObject> toList();
375409
List<AggregateResult> toAggregated();
410+
List<AggregateResultProxy> toAggregatedProxy();
376411
Map<Id, SObject> toMap();
377412
Map<String, SObject> toMap(SObjectField keyField);
378413
Map<String, SObject> toMap(String relationshipName, SObjectField targetKeyField);

website/docs/docs/build-cached-selector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Check examples in the [repository](https://github.com/beyond-the-cloud-dev/soql-
88

99

1010
SOQL-Lib is agile, so you can adjust the solution according to your needs.
11-
We don't force one approach over another, you can choose your own. Here are our propositions:
11+
We don't force one approach over another; you can choose your own. Here are our suggestions:
1212

1313
## A - Inheritance - extends SOQLCache, implements Interface + static (Recommended)
1414

website/docs/docs/build-your-selector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Check examples in the [repository](https://github.com/beyond-the-cloud-dev/soql-
99

1010

1111
SOQL-Lib is agile, so you can adjust the solution according to your needs.
12-
We don't force one approach over another, you can choose your own. Here are our propositions:
12+
We don't force one approach over another; you can choose your own. Here are our suggestions:
1313

1414
## A - Inheritance - extends SOQL, implements Interface + static (Recommended)
1515

0 commit comments

Comments
 (0)