Skip to content

Commit 623049f

Browse files
committed
documentation
1 parent 0420101 commit 623049f

File tree

3 files changed

+95
-133
lines changed

3 files changed

+95
-133
lines changed

website/docs/soql/advanced/design.md

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -14,107 +14,6 @@ You don't need to think about dependencies; everything you need is stored in [SO
1414
Different clauses are encapsulated in small, inner classes.
1515
All crucial information is kept at the top of the class, so developers can use it even without reading the documentation.
1616

17-
## Class Architecture
18-
19-
The following diagram shows the internal structure and relationships between the main classes and interfaces in SOQL Lib:
20-
21-
## Core Architecture
22-
23-
```mermaid
24-
flowchart LR
25-
%% Main Vertical Column - Left Side
26-
subgraph MainComponents ["Main Architecture"]
27-
direction TB
28-
SOQL["SOQL<br/>(Main Class)<br/>implements Queryable"]
29-
SoqlBuilder["SoqlBuilder<br/>(Query Construction)"]
30-
Executor["Executor<br/>(Database Operations)"]
31-
Converter["Converter<br/>(Result Transformation)"]
32-
Binder["Binder<br/>(Variable Binding)"]
33-
34-
SOQL --> SoqlBuilder
35-
SOQL --> Executor
36-
SOQL --> Converter
37-
SOQL --> Binder
38-
end
39-
40-
%% Implementation Details - Right Side
41-
subgraph FieldDetails ["Field System"]
42-
direction TB
43-
PlainFields["PlainFields"]
44-
RelationshipFields["RelationshipFields"]
45-
AggregateFunctionsFields["AggregateFunctionsFields"]
46-
FunctionsFields["FunctionsFields"]
47-
end
48-
49-
subgraph FilterDetails ["Filter System"]
50-
direction TB
51-
SoqlFilterGroup["SoqlFilterGroup<br/>implements FilterGroup"]
52-
SoqlFilter["SoqlFilter<br/>implements Filter"]
53-
SoqlJoinQuery["SoqlJoinQuery<br/>implements InnerJoin"]
54-
55-
SoqlFilterGroup --> SoqlFilter
56-
SoqlFilter --> SoqlJoinQuery
57-
end
58-
59-
subgraph HavingDetails ["Having System"]
60-
direction TB
61-
SoqlHavingFilterGroup["SoqlHavingFilterGroup<br/>implements HavingFilterGroup"]
62-
SoqlHavingFilter["SoqlHavingFilter<br/>implements HavingFilter"]
63-
64-
SoqlHavingFilterGroup --> SoqlHavingFilter
65-
end
66-
67-
subgraph SharingDetails ["Sharing System"]
68-
direction TB
69-
InheritedSharing["InheritedSharing"]
70-
WithSharing["WithSharing"]
71-
WithoutSharing["WithoutSharing"]
72-
end
73-
74-
subgraph MockingDetails ["Mocking System"]
75-
direction TB
76-
SObjectMock["SObjectMock"]
77-
CountMock["CountMock"]
78-
AggregateResultProxys["AggregateResultProxys"]
79-
SoqlAggregateResultProxy["SoqlAggregateResultProxy<br/>implements AggregateResultProxy"]
80-
RandomIdGenerator["RandomIdGenerator"]
81-
82-
AggregateResultProxys --> SoqlAggregateResultProxy
83-
SObjectMock --> RandomIdGenerator
84-
end
85-
86-
subgraph OtherComponents ["Other Components"]
87-
direction TB
88-
SoqlSubQuery["SoqlSubQuery<br/>implements SubQuery"]
89-
SoqlOrderBy["SoqlOrderBy"]
90-
SoqlFrom["SoqlFrom"]
91-
SoqlGroupBy["SoqlGroupBy"]
92-
SoqlLimit["SoqlLimit"]
93-
SoqlOffset["SoqlOffset"]
94-
SoqlFor["SoqlFor"]
95-
SoqlScope["SoqlScope"]
96-
SoqlDataCategoryFilter["SoqlDataCategoryFilter<br/>implements DataCategoryFilter"]
97-
end
98-
99-
%% Connections from Main to Details
100-
SoqlBuilder -.-> FieldDetails
101-
SoqlBuilder -.-> FilterDetails
102-
SoqlBuilder -.-> HavingDetails
103-
SoqlBuilder -.-> OtherComponents
104-
Executor -.-> SharingDetails
105-
Executor -.-> MockingDetails
106-
107-
%% Styling
108-
classDef mainClass fill:#e1f5fe,stroke:#01579b,stroke-width:4px,font-size:16px
109-
classDef coreComponent fill:#f3e5f5,stroke:#4a148c,stroke-width:3px,font-size:14px
110-
classDef implementation fill:#fff3e0,stroke:#e65100,stroke-width:1px,font-size:11px
111-
classDef subgraphStyle fill:#f9f9f9,stroke:#666,stroke-width:2px
112-
113-
class SOQL mainClass
114-
class SoqlBuilder,Executor,Converter,Binder coreComponent
115-
class PlainFields,RelationshipFields,AggregateFunctionsFields,FunctionsFields,SoqlFilterGroup,SoqlFilter,SoqlJoinQuery,SoqlHavingFilterGroup,SoqlHavingFilter,SoqlSubQuery,SoqlOrderBy,SoqlFrom,SoqlGroupBy,SoqlLimit,SoqlOffset,SoqlFor,SoqlScope,SoqlDataCategoryFilter,InheritedSharing,WithSharing,WithoutSharing,SObjectMock,CountMock,AggregateResultProxys,SoqlAggregateResultProxy,RandomIdGenerator implementation
116-
```
117-
11817
## Public API
11918

12019
### Static Factory Methods

website/docs/soql/build-selector.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
---
2-
slug: '/building-selector'
32
sidebar_position: 17
43
---
54

65
# Building Your Selector
76

7+
:::info[New Selectors Approach!]
8+
9+
The concept of selectors in SOQL Lib is different from FFLib Selectors!
10+
11+
SOQL Lib Selectors:
12+
- Not all queries are kept in selectors. Only very generic methods are maintained in the selector class like byParentId, bySource, byRecordType, byId. Each method returns an instance of that selector. This approach allows you to chain methods from the selector class.
13+
- The selector constructor keeps default configurations, such as default fields, sharing mode, and field-level security.
14+
:::
15+
816
Check examples in the [repository](https://github.com/beyond-the-cloud-dev/soql-lib/tree/main/force-app/main/default/classes/examples/standard-selectors).
917

18+
SOQL Lib is agile, so you can adjust the solution according to your needs.
1019

11-
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 suggestions:
20+
**We don't force one approach over another; you can choose your own**.
1321

14-
## A - Inheritance - extends SOQL, implements Interface + static (Recommended)
22+
## A - Inheritance - extends SOQL, implements Interface + static _(Recommended)_
1523

1624
Most Flexible Approach:
1725
- The selector constructor keeps default configurations, such as default fields, sharing mode, and field-level security.
1826
- Only very generic methods are maintained in the selector class, and each method returns an instance of that selector. This approach allows you to chain methods from the selector class.
1927
- Additional fields, more complex conditions, ordering, limits, and other SOQL clauses can be built where they are needed (for example, in a controller method).
2028

21-
```apex
29+
```apex title="SOQL_Account.cls"
2230
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
2331
public static SOQL_Account query() {
2432
return new SOQL_Account();
@@ -33,20 +41,18 @@ public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selecto
3341
}
3442
3543
public SOQL_Account byIndustry(String industry) {
36-
with(Account.Industry)
37-
.whereAre(Filter.with(Account.Industry).equal(industry));
44+
whereAre(Filter.with(Account.Industry).equal(industry));
3845
return this;
3946
}
4047
4148
public SOQL_Account byParentId(Id parentId) {
42-
with(Account.ParentId)
43-
.whereAre(Filter.with(Account.ParentId).equal(parentId));
49+
whereAre(Filter.with(Account.ParentId).equal(parentId));
4450
return this;
4551
}
4652
}
4753
```
4854

49-
```apex
55+
```apex title="ExampleController.cls"
5056
public with sharing class ExampleController {
5157
@AuraEnabled
5258
public static List<Account> getPartnerAccounts(String accountName) {
@@ -72,7 +78,7 @@ public with sharing class ExampleController {
7278

7379
Use `SOQL.Selector` and create `static` methods.
7480

75-
```apex
81+
```apex title="SOQL_Contact.cls"
7682
public inherited sharing class SOQL_Contact implements SOQL.Selector {
7783
public static SOQL query() {
7884
// default settings
@@ -93,9 +99,8 @@ public inherited sharing class SOQL_Contact implements SOQL.Selector {
9399
}
94100
```
95101

96-
```apex
102+
```apex title="ExampleController.cls"
97103
public with sharing class ExampleController {
98-
99104
@AuraEnabled
100105
public static List<Contact> getContactsByRecordType(String recordType) {
101106
return SOQL_Contact.byRecordType(recordType)
@@ -117,7 +122,7 @@ public with sharing class ExampleController {
117122

118123
## C - Inheritance - extends SOQL + non-static
119124

120-
```apex
125+
```apex title="SOQL_Account.cls"
121126
public inherited sharing class SOQL_Account extends SOQL {
122127
public SOQL_Account() {
123128
super(Account.SObjectType);
@@ -145,7 +150,7 @@ public inherited sharing class SOQL_Account extends SOQL {
145150
}
146151
```
147152

148-
```apex
153+
```apex title="ExampleController.cls"
149154
public with sharing class ExampleController {
150155
@AuraEnabled
151156
public static List<Account> getPartnerAccounts(String accountName) {
@@ -176,9 +181,9 @@ public with sharing class ExampleController {
176181

177182
## D - Composition - implements Interface + non-static
178183

179-
Very useful when you have different teams/streams that need different query configurations.
184+
This approach is very useful when you have different teams/streams that need different query configurations.
180185

181-
```apex
186+
```apex title="BaseAccountSelector.cls"
182187
public inherited sharing virtual class BaseAccountSelector implements SOQL.Selector {
183188
public virtual SOQL query() {
184189
return SOQL.of(Account.SObjectType)
@@ -193,7 +198,7 @@ public inherited sharing virtual class BaseAccountSelector implements SOQL.Selec
193198
}
194199
```
195200

196-
```apex
201+
```apex title="MyTeam_AccountSelector.cls"
197202
public with sharing class MyTeam_AccountSelector extends BaseAccountSelector implements SOQL.Selector {
198203
public override SOQL query() {
199204
return SOQL.of(Account.SObjectType)
@@ -204,9 +209,8 @@ public with sharing class MyTeam_AccountSelector extends BaseAccountSelector imp
204209
}
205210
```
206211

207-
```apex
212+
```apex title="ExampleController.cls"
208213
public with sharing class ExampleController {
209-
210214
public static List<Account> getAccounts(String accountName) {
211215
return new MyTeam_AccountSelector().query()
212216
.with(Account.BillingCity, Account.BillingCountry)
@@ -216,8 +220,8 @@ public with sharing class ExampleController {
216220
217221
public static List<Account> getAccountsByRecordType(String recordType) {
218222
return new MyTeam_AccountSelector().byRecordType(recordType)
219-
.with(Account.ParentId)
220-
.toList();
223+
.with(Account.ParentId)
224+
.toList();
221225
}
222226
}
223227
```
@@ -226,7 +230,7 @@ public with sharing class ExampleController {
226230

227231
Create Selectors in your own way.
228232

229-
```apex
233+
```apex title="SOQL_Account.cls"
230234
public inherited sharing class SOQL_Account {
231235
public static SOQL query {
232236
return SOQL.of(Account.SObjectType)
@@ -241,9 +245,8 @@ public inherited sharing class SOQL_Account {
241245
}
242246
```
243247

244-
```apex
248+
```apex title="ExampleController.cls"
245249
public with sharing class ExampleController {
246-
247250
public static List<Account> getAccounts(String accountName) {
248251
return SOQL_Account.query
249252
.with(Account.BillingCity, Account.BillingCountry)
@@ -253,18 +256,17 @@ public with sharing class ExampleController {
253256
254257
public static List<Account> getAccountsByRecordType(String recordType) {
255258
return SOQL_Account.byRecordType(recordType)
256-
.with(Account.ParentId)
257-
.toList();
259+
.with(Account.ParentId)
260+
.toList();
258261
}
259262
}
260263
```
261264

262265
## F - FFLib Approach
263266

264-
```apex
265-
266-
public inherited sharing class SOQL_Opportunity extends SOQL {
267-
public SOQL_Opportunity() {
267+
```apex title="OpportunitySelector.cls"
268+
public inherited sharing class OpportunitySelector extends SOQL {
269+
public OpportunitySelector() {
268270
super(Opportunity.SObjectType);
269271
// default settings
270272
with(Opportunity.Id, Opportunity.AccountId)

website/docs/soql/getting-started.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,65 @@
22
sidebar_position: 10
33
---
44

5-
# Getting Started
5+
# Getting Started
6+
7+
The main module of the SOQL Lib consists of two concepts: **SOQL Builder** and **SOQL Selectors**.
8+
9+
**SOQL Builder**
10+
11+
Our library does not force developers to create selectors. Queries can be built directly via fluent API provided by the lib.
12+
13+
```apex
14+
// SELECT Id FROM Account WITH USER_MODE
15+
List<Account> accounts = SOQL.of(Account.SObjectType).toList();
16+
```
17+
18+
```apex
19+
// SELECT Id, Name, Industry FROM Account WITH USER_MODE
20+
List<Account> accounts = SOQL.of(Account.SObjectType)
21+
.with(Account.Id, Account.Name, Account.Industry)
22+
.toList();
23+
```
24+
25+
**SOQL Selectors** _(Recommended)_
26+
27+
However, we recommend building a selector per `SObjectType`.
28+
29+
Selectors allow you to set default SOQL settings for a given `SObjectType` and keep all reusable queries in one place.
30+
Check how to build a selector in the [Build Your Selector](./build-selector.md) section.
31+
32+
```apex title="SOQL_Contact.cls"
33+
public inherited sharing class SOQL_Contact extends SOQL implements SOQL.Selector {
34+
public static SOQL_Contact query() {
35+
return new SOQL_Contact();
36+
}
37+
38+
private SOQL_Contact() {
39+
super(Contact.SObjectType);
40+
// default settings
41+
with(Contact.Id, Contact.Name, Contact.AccountId);
42+
systemMode();
43+
withoutSharing();
44+
}
45+
46+
public SOQL_Contact byAccountId(Id accountId) {
47+
whereAre(Filter.with(Contact.AccountId).equal(accountId));
48+
return this;
49+
}
50+
51+
public SOQL_Contact bySource(String source) {
52+
whereAre(Filter.with(Contact.ContactSource).equal(source));
53+
return this;
54+
}
55+
}
56+
```
57+
58+
```apex title="Selector Usage"
59+
List<Contact> contacts = SOQL_Contact.query()
60+
.byAccountId(...)
61+
.bySource('Web')
62+
.with(Contact.Email)
63+
.toList();
64+
```
65+
66+

0 commit comments

Comments
 (0)