Skip to content

Commit 0599266

Browse files
committed
refactoring
1 parent 88cffe5 commit 0599266

File tree

6 files changed

+48
-106
lines changed

6 files changed

+48
-106
lines changed

force-app/main/default/classes/SOQL_Test.cls

Lines changed: 38 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ private class SOQL_Test {
117117
// Test
118118
String soql = SOQL.of(Account.SObjectType)
119119
.with(new List<SObjectField>{
120-
Account.Name, Account.BillingCity
120+
Account.Id,
121+
Account.Name,
122+
Account.Industry,
123+
Account.AccountNumber,
124+
Account.AnnualRevenue,
125+
Account.BillingCity
121126
}).toString();
122127

123128
// Verify
124-
Assert.areEqual('SELECT Name, BillingCity FROM Account', soql);
129+
Assert.areEqual('SELECT Id, Name, Industry, AccountNumber, AnnualRevenue, BillingCity FROM Account', soql);
125130
}
126131

127132
@IsTest
@@ -139,9 +144,7 @@ private class SOQL_Test {
139144
static void withRelatedField() {
140145
// Test
141146
String soql = SOQL.of(Account.SObjectType)
142-
.with(new List<SObjectField>{
143-
Account.Name, Account.BillingCity
144-
})
147+
.with(Account.Name, Account.BillingCity)
145148
.with('CreatedBy', User.Name)
146149
.toString();
147150

@@ -153,9 +156,7 @@ private class SOQL_Test {
153156
static void withTwoRelatedFields() {
154157
// Test
155158
String soql = SOQL.of(Account.SObjectType)
156-
.with(new List<SObjectField>{
157-
Account.Name, Account.BillingCity
158-
})
159+
.with(Account.Name, Account.BillingCity)
159160
.with('CreatedBy', User.Id, User.Name)
160161
.toString();
161162

@@ -167,9 +168,7 @@ private class SOQL_Test {
167168
static void withThreeRelatedFields() {
168169
// Test
169170
String soql = SOQL.of(Account.SObjectType)
170-
.with(new List<SObjectField>{
171-
Account.Name, Account.BillingCity
172-
})
171+
.with(Account.Name, Account.BillingCity)
173172
.with('CreatedBy', User.Id, User.Name, User.Alias)
174173
.toString();
175174

@@ -181,9 +180,7 @@ private class SOQL_Test {
181180
static void withFourRelatedFields() {
182181
// Test
183182
String soql = SOQL.of(Account.SObjectType)
184-
.with(new List<SObjectField>{
185-
Account.Name, Account.BillingCity
186-
})
183+
.with(Account.Name, Account.BillingCity)
187184
.with('CreatedBy', User.Id, User.Name, User.Alias, User.City)
188185
.toString();
189186

@@ -195,9 +192,7 @@ private class SOQL_Test {
195192
static void withFiveRelatedFields() {
196193
// Test
197194
String soql = SOQL.of(Account.SObjectType)
198-
.with(new List<SObjectField>{
199-
Account.Name, Account.BillingCity
200-
})
195+
.with(Account.Name, Account.BillingCity)
201196
.with('CreatedBy', User.Id, User.Name, User.Alias, User.City, User.CompanyName)
202197
.toString();
203198

@@ -209,9 +204,7 @@ private class SOQL_Test {
209204
static void withRelatedFields() {
210205
// Test
211206
String soql = SOQL.of(Account.SObjectType)
212-
.with(new List<SObjectField>{
213-
Account.Name, Account.BillingCity
214-
})
207+
.with(Account.Name, Account.BillingCity)
215208
.with('CreatedBy', new List<SObjectField>{
216209
User.Id, User.Name
217210
}).toString();
@@ -226,9 +219,7 @@ private class SOQL_Test {
226219
static void subQueryField() {
227220
// Test
228221
String soql = SOQL.of(Account.SObjectType)
229-
.with(new List<SObjectField>{
230-
Account.Name
231-
})
222+
.with(Account.Name)
232223
.with(SOQL.SubQuery.of('Contacts')
233224
.with(Contact.Id)
234225
).toString();
@@ -241,9 +232,7 @@ private class SOQL_Test {
241232
static void subQueryTwoFields() {
242233
// Test
243234
String soql = SOQL.of(Account.SObjectType)
244-
.with(new List<SObjectField>{
245-
Account.Name
246-
})
235+
.with(Account.Name)
247236
.with(SOQL.SubQuery.of('Contacts')
248237
.with(Contact.Id, Contact.Name)
249238
).toString();
@@ -256,9 +245,7 @@ private class SOQL_Test {
256245
static void subQueryThreeFields() {
257246
// Test
258247
String soql = SOQL.of(Account.SObjectType)
259-
.with(new List<SObjectField>{
260-
Account.Name
261-
})
248+
.with(Account.Name)
262249
.with(SOQL.SubQuery.of('Contacts')
263250
.with(Contact.Id, Contact.Name, Contact.AccountId)
264251
).toString();
@@ -271,9 +258,7 @@ private class SOQL_Test {
271258
static void subQueryFourFields() {
272259
// Test
273260
String soql = SOQL.of(Account.SObjectType)
274-
.with(new List<SObjectField>{
275-
Account.Name
276-
})
261+
.with(Account.Name)
277262
.with(SOQL.SubQuery.of('Contacts')
278263
.with(Contact.Id, Contact.Name, Contact.AccountId, Contact.Email)
279264
).toString();
@@ -286,9 +271,7 @@ private class SOQL_Test {
286271
static void subQueryFiveFields() {
287272
// Test
288273
String soql = SOQL.of(Account.SObjectType)
289-
.with(new List<SObjectField>{
290-
Account.Name
291-
})
274+
.with(Account.Name)
292275
.with(SOQL.SubQuery.of('Contacts')
293276
.with(Contact.Id, Contact.Name, Contact.AccountId, Contact.Email, Contact.Phone)
294277
).toString();
@@ -301,9 +284,7 @@ private class SOQL_Test {
301284
static void subQueryFields() {
302285
// Test
303286
String soql = SOQL.of(Account.SObjectType)
304-
.with(new List<SObjectField>{
305-
Account.Name
306-
})
287+
.with(Account.Name)
307288
.with(SOQL.SubQuery.of('Contacts')
308289
.with(new List<SObjectField>{
309290
Contact.Id, Contact.Name
@@ -318,13 +299,9 @@ private class SOQL_Test {
318299
static void subQueryRelatedFields() {
319300
// Test
320301
String soql = SOQL.of(Account.SObjectType)
321-
.with(new List<SObjectField>{
322-
Account.Name
323-
})
302+
.with(Account.Name)
324303
.with(SOQL.SubQuery.of('Contacts')
325-
.with(new List<SObjectField>{
326-
Contact.Id, Contact.Name
327-
})
304+
.with(Contact.Id, Contact.Name)
328305
.with('CreatedBy', new List<SObjectField>{
329306
User.Id, User.Name
330307
})
@@ -338,13 +315,9 @@ private class SOQL_Test {
338315
static void subQueryWhere() {
339316
// Test
340317
String soql = SOQL.of(Account.SObjectType)
341-
.with(new List<SObjectField>{
342-
Account.Name
343-
})
318+
.with(Account.Name)
344319
.with(SOQL.SubQuery.of('Contacts')
345-
.with(new List<SObjectField>{
346-
Contact.Id, Contact.Name
347-
})
320+
.with(Contact.Id, Contact.Name)
348321
.whereAre(SOQL.Filter.with(Contact.LastName).equal('Doe'))
349322
).toString();
350323

@@ -356,13 +329,9 @@ private class SOQL_Test {
356329
static void subQueryOrderBy() {
357330
// Test
358331
String soql = SOQL.of(Account.SObjectType)
359-
.with(new List<SObjectField>{
360-
Account.Name
361-
})
332+
.with(Account.Name)
362333
.with(SOQL.SubQuery.of('Contacts')
363-
.with(new List<SObjectField>{
364-
Contact.Id, Contact.Name
365-
})
334+
.with(Contact.Id, Contact.Name)
366335
.orderBy(Contact.Name)
367336
.sortDesc()
368337
.nullsLast()
@@ -376,13 +345,9 @@ private class SOQL_Test {
376345
static void subQueryOrderByRelated() {
377346
// Test
378347
String soql = SOQL.of(Account.SObjectType)
379-
.with(new List<SObjectField>{
380-
Account.Name
381-
})
348+
.with(Account.Name)
382349
.with(SOQL.SubQuery.of('Contacts')
383-
.with(new List<SObjectField>{
384-
Contact.Id, Contact.Name
385-
})
350+
.with(Contact.Id, Contact.Name)
386351
.orderBy('CreatedBy', User.Name)
387352
.sortDesc()
388353
.nullsLast()
@@ -396,13 +361,9 @@ private class SOQL_Test {
396361
static void subQuerySetLimit() {
397362
// Test
398363
String soql = SOQL.of(Account.SObjectType)
399-
.with(new List<SObjectField>{
400-
Account.Name
401-
})
364+
.with(Account.Name)
402365
.with(SOQL.SubQuery.of('Contacts')
403-
.with(new List<SObjectField>{
404-
Contact.Id, Contact.Name
405-
})
366+
.with(Contact.Id, Contact.Name)
406367
.setLimit(10)
407368
).toString();
408369

@@ -414,13 +375,9 @@ private class SOQL_Test {
414375
static void subQueryOffset() {
415376
// Test
416377
String soql = SOQL.of(Account.SObjectType)
417-
.with(new List<SObjectField>{
418-
Account.Name
419-
})
378+
.with(Account.Name)
420379
.with(SOQL.SubQuery.of('Contacts')
421-
.with(new List<SObjectField>{
422-
Contact.Id, Contact.Name
423-
})
380+
.with(Contact.Id, Contact.Name)
424381
.offset(100)
425382
).toString();
426383

@@ -432,13 +389,9 @@ private class SOQL_Test {
432389
static void subQueryForReference() {
433390
// Test
434391
String soql = SOQL.of(Account.SObjectType)
435-
.with(new List<SObjectField>{
436-
Account.Name
437-
})
392+
.with(Account.Name)
438393
.with(SOQL.SubQuery.of('Contacts')
439-
.with(new List<SObjectField>{
440-
Contact.Id, Contact.Name
441-
})
394+
.with(Contact.Id, Contact.Name)
442395
.forReference()
443396
).toString();
444397

@@ -450,13 +403,9 @@ private class SOQL_Test {
450403
static void subQueryForView() {
451404
// Test
452405
String soql = SOQL.of(Account.SObjectType)
453-
.with(new List<SObjectField>{
454-
Account.Name
455-
})
406+
.with(Account.Name)
456407
.with(SOQL.SubQuery.of('Contacts')
457-
.with(new List<SObjectField>{
458-
Contact.Id, Contact.Name
459-
})
408+
.with(Contact.Id, Contact.Name)
460409
.forView()
461410
).toString();
462411

@@ -787,9 +736,7 @@ private class SOQL_Test {
787736

788737
// Test
789738
SOQL builder = SOQL.of(Account.SObjectType)
790-
.with(new List<SObjectField>{
791-
Account.Name, Account.BillingCity
792-
})
739+
.with(Account.Name, Account.BillingCity)
793740
.whereAre(SOQL.Filter.with(Account.Name).notIn(names));
794741

795742
// Verify
@@ -956,7 +903,7 @@ private class SOQL_Test {
956903
.whereAre(SOQL.Filter.with(Account.Id).notIn(
957904
SOQL.InnerJoin.of(Contact.SObjectType)
958905
.with(Contact.AccountId)
959-
.whereAre(SOQL.Filter.with(Contact.Name).equal('My Contact'))
906+
.whereAre(SOQL.Filter.name().equal('My Contact'))
960907
));
961908

962909
// Verify
@@ -1004,9 +951,7 @@ private class SOQL_Test {
1004951
static void groupBy() {
1005952
// Test
1006953
String soql = SOQL.of(Lead.SObjectType)
1007-
.with(new List<SObjectField>{
1008-
Lead.LeadSource
1009-
})
954+
.with(Lead.LeadSource)
1010955
.groupBy(Lead.LeadSource)
1011956
.toString();
1012957

website/docs/basic-features.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ Developer can skip FLS by adding `.systemMode()` and `.withSharing()`.
7878

7979
```apex
8080
// Query executed in without sharing
81-
SOQL.of(Account.SObjectType).with(Account.Id, Account.Name)
81+
SOQL.of(Account.SObjectType)
82+
.with(Account.Id, Account.Name)
8283
.systemMode()
8384
.withSharing()
8485
.toList();
@@ -121,7 +122,7 @@ public with sharing class ExampleController {
121122
return AccountSelector.query()
122123
.with(Account.BillingCity, Account.BillingCountry)
123124
.whereAre(SOQL.FilterGroup
124-
.add(SOQL.Filter.with(Account.Name).contains(accountName))
125+
.add(SOQL.Filter.name().contains(accountName))
125126
.add(SOQL.Filter.recordType().equal('Partner'))
126127
)
127128
.mockId('ExampleController.getPartnerAccounts')

website/docs/examples/debug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public with sharing class MyController {
2727
.whereAre(SOQL.FilterGroup
2828
.add(SOQL.Filter.id().equal('0013V00000WNCw4QAH'))
2929
.add(SOQL.Filter.name().contains('Test'))
30-
.conditionLogic('1 OR 2')
30+
.anyConditionMatching()
3131
)
3232
.preview()
3333
.toList();

website/docs/examples/mocking.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public with sharing class ExampleController {
1919
2020
public static List<Account> getAccountByName(String accountName) {
2121
return AccountSelector.query()
22-
.with(Account.BillingCity)
23-
.with(Account.BillingCountry)
22+
.with(Account.BillingCity, Account.BillingCountry)
2423
.whereAre(SOQL.Filter.name().contains(accountName))
2524
.setLimit(1)
2625
.mockId('ExampleController.getAccountByName')
@@ -60,8 +59,7 @@ public with sharing class ExampleController {
6059
6160
public static List<Account> getPartnerAccounts(String accountName) {
6261
return AccountSelector.query()
63-
.with(Account.BillingCity)
64-
.with(Account.BillingCountry)
62+
.with(Account.BillingCity, Account.BillingCountry)
6563
.whereAre(SOQL.FilterGroup
6664
.add(SOQL.Filter.name().contains(accountName))
6765
.add(SOQL.Filter.recordType().equal('Partner'))
@@ -147,8 +145,7 @@ public with sharing class ExampleController {
147145
148146
public static List<Account> getPartnerAccounts(String accountName) {
149147
return AccountSelector.query()
150-
.with(Account.BillingCity)
151-
.with(Account.BillingCountry)
148+
.with(Account.BillingCity, Account.BillingCountry)
152149
.whereAre(SOQL.FilterGroup
153150
.add(SOQL.Filter.name().contains(accountName))
154151
.add(SOQL.Filter.recordType().equal('Partner'))

website/docs/examples/where.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public with sharing class MyController {
2727
.whereAre(SOQL.FilterGroup
2828
.add(SOQL.Filter.id().equal(accountId))
2929
.add(SOQL.Filter.with(Account.Name).contains(accountName))
30-
.conditionLogic('1 OR 2')
30+
.anyConditionMatching() // OR
3131
)
3232
.toList();
3333
}

website/docs/key-concepts.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ SOQL Builder allows to build query dynamically and execute it.
3232
```apex
3333
// SELECT Id, Name, Industry FROM Account
3434
List<Account> accounts = SOQL.of(Account.SObjectType)
35-
.with(new List<SObjectField>{
36-
Account.Id, Account.Name, Account.Industry
37-
}).toList();
35+
.with(Account.Id, Account.Name, Account.Industry)
36+
.toList();
3837
```
3938

4039
## SOQL Selector

0 commit comments

Comments
 (0)