Skip to content

Commit ba513b2

Browse files
committed
documentation
1 parent 22a702b commit ba513b2

File tree

4 files changed

+129
-5
lines changed

4 files changed

+129
-5
lines changed

website/docs/docs/basic-features.md

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,130 @@ SOQL.of(Account.SObjectType)
4646
}
4747
```
4848

49+
50+
## Minimalistic Selectors
51+
52+
The selector constructor maintains default configurations such as default fields, sharing mode, and field-level security settings. Only essential, reusable methods are maintained in the selector class, with each method returning an instance of the selector to enable method chaining.
53+
54+
Additional fields, complex conditions, ordering, limits, and other SOQL clauses can be built dynamically where they are needed (for example, in controller methods), keeping the selector focused on core functionality.
55+
56+
```apex
57+
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
58+
public static final String MOCK_ID = 'SOQL_Account';
59+
60+
public static SOQL_Account query() {
61+
return new SOQL_Account();
62+
}
63+
64+
private SOQL_Account() {
65+
super(Account.SObjectType);
66+
// Default configuration
67+
with(Account.Id, Account.Name);
68+
systemMode();
69+
withoutSharing();
70+
mockId(MOCK_ID);
71+
}
72+
73+
public SOQL_Account byType(String type) {
74+
whereAre(Filter.with(Account.Type).equal(type));
75+
return this;
76+
}
77+
78+
public SOQL_Account byIndustry(String industry) {
79+
whereAre(Filter.with(Account.Industry).equal(industry));
80+
return this;
81+
}
82+
83+
public SOQL_Account byParentId(Id parentId) {
84+
whereAre(Filter.with(Account.ParentId).equal(parentId));
85+
return this;
86+
}
87+
88+
public SOQL_Account byOwnerId(Id ownerId) {
89+
whereAre(Filter.with(Account.OwnerId).equal(ownerId));
90+
return this;
91+
}
92+
}
93+
```
94+
95+
96+
**Usage Example:**
97+
98+
```apex
99+
// Basic usage with default configuration
100+
List<Account> allAccounts = SOQL_Account.query().toList();
101+
102+
// Chain selector methods
103+
List<Account> techPartners = SOQL_Account.query()
104+
.byType('Partner')
105+
.byIndustry('Technology')
106+
.toList();
107+
108+
// Extend with additional fields and clauses dynamically
109+
List<Account> topAccounts = SOQL_Account.query()
110+
.byIndustry('Technology')
111+
.with(Account.AnnualRevenue, Account.BillingCity)
112+
.whereAre(SOQL.Filter.with(Account.AnnualRevenue).greaterThan(1000000))
113+
.orderBy(Account.AnnualRevenue).sortDesc()
114+
.setLimit(10)
115+
.toList();
116+
```
117+
118+
## Minimal Fields
119+
120+
SOQL Lib selectors are designed to include only a minimal set of default fields in their constructor, typically just essential identifiers and commonly used fields. This approach significantly improves query performance and promotes reusability by avoiding unnecessary data retrieval.
121+
122+
**Design Philosophy:**
123+
The selector constructor defines the minimum viable field set that covers the majority of use cases. Additional fields are added dynamically where they are actually needed, following the principle of "pull only what you need, when you need it."
124+
125+
```apex
126+
public inherited sharing class SOQL_Contact extends SOQL implements SOQL.Selector {
127+
public static SOQL_Contact query() {
128+
return new SOQL_Contact();
129+
}
130+
131+
private SOQL_Contact() {
132+
super(Contact.SObjectType);
133+
// Minimal default fields - only essentials
134+
with(Contact.Id, Contact.Name, Contact.AccountId)
135+
.systemMode()
136+
.withoutSharing();
137+
}
138+
139+
public SOQL_Contact byAccountId(Id accountId) {
140+
whereAre(Filter.with(Contact.AccountId).equal(accountId));
141+
return this;
142+
}
143+
}
144+
```
145+
146+
**Dynamic Field Addition:**
147+
Additional fields are added at the point of use, keeping the selector lean while providing flexibility for specific business requirements.
148+
149+
```apex
150+
public with sharing class ExampleController {
151+
@AuraEnabled
152+
public static List<Contact> getContactDetails(Id accountId) {
153+
return SOQL_Contact.query()
154+
.byAccountId(accountId)
155+
// Add fields only when needed
156+
.with(Contact.Email, Contact.Phone, Contact.Department, Contact.Title)
157+
.with('Account', Account.Name, Account.Industry)
158+
.orderBy(Contact.LastName)
159+
.setLimit(100)
160+
.toList();
161+
}
162+
163+
@AuraEnabled
164+
public static List<Contact> getBasicContacts(Id accountId) {
165+
// Uses only default fields (Id, Name, AccountId)
166+
return SOQL_Contact.query()
167+
.byAccountId(accountId)
168+
.toList();
169+
}
170+
}
171+
```
172+
49173
## Control FLS
50174

51175
[AccessLevel Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_AccessLevel.htm)
@@ -353,7 +477,7 @@ public List<Account> getAccounts() {
353477
Did you know that?
354478

355479
- Retrieving data from the cache takes less than 10ms.
356-
- Read operations (SOQL) account for approximately 70% of an orgs activity.
480+
- Read operations (SOQL) account for approximately 70% of an org's activity.
357481

358482
Cache can significantly boost your org's performance. You can use it for objects like:
359483

website/docs/docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar_position: 15
77

88
**System Requirements**
99

10-
- API: 63.0
10+
- API: 64.0
1111

1212
## Deploy
1313

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 95
2+
sidebar_position: 96
33
---
44

55
# OFFSET

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar_position: 150
88
> All examples use inline queries built with the SOQL Lib Query Builder.
99
> If you are using a selector, replace `SOQL.of(...)` with `YourSelectorName.query()`.
1010
11-
## toId()
11+
## toId
1212

1313
**Apex**
1414

@@ -22,7 +22,7 @@ Id accountId = [SELECT Id FROM Account LIMIT 1].Id;
2222
Id accountId = SOQL.of(Account.SObjectType).setLimit(1).toId();
2323
```
2424

25-
## toIds()
25+
## toIds
2626

2727
**Apex**
2828

0 commit comments

Comments
 (0)