Skip to content

Commit ccb1c17

Browse files
authored
Release v2.3.0 [IN PROGRESS] (#80)
* SOQL With List of Strings (#79) * BTC-80 - Add Count when toInteger is invoke (#81) * BTC-80 - Add Count when toInteger is invoke * BTC-80 - areCountsEmpty * documentation update
1 parent b8e7d34 commit ccb1c17

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public virtual inherited sharing class SOQL implements Queryable {
5151
Queryable with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4);
5252
Queryable with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5);
5353
Queryable with(List<SObjectField> fields);
54+
Queryable with(Iterable<String> fields);
5455
Queryable with(String fields);
5556
Queryable with(SObjectField field, String alias);
5657
Queryable with(String relationshipName, SObjectField field);
@@ -286,6 +287,10 @@ public virtual inherited sharing class SOQL implements Queryable {
286287
return this;
287288
}
288289

290+
public SOQL with(Iterable<String> fields) {
291+
return with(String.join(fields, ','));
292+
}
293+
289294
public SOQL with(String fields) {
290295
builder.fields.with(fields);
291296
return this;
@@ -525,6 +530,9 @@ public virtual inherited sharing class SOQL implements Queryable {
525530
}
526531

527532
public Integer toInteger() {
533+
if (builder.fields.areCountsEmpty()) {
534+
count();
535+
}
528536
return executor.toInteger(builder.toString(), binder.getBindingMap());
529537
}
530538

@@ -732,6 +740,10 @@ public virtual inherited sharing class SOQL implements Queryable {
732740
fields.clear();
733741
}
734742

743+
public Boolean areCountsEmpty() {
744+
return counts.isEmpty();
745+
}
746+
735747
public override String toString() {
736748
if (fields.isEmpty() && counts.isEmpty()) {
737749
return 'SELECT Id';

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ private class SOQL_Test {
135135
Assert.areEqual('SELECT Id, Name, Industry, AccountNumber, AnnualRevenue, BillingCity FROM Account', soql);
136136
}
137137

138+
@IsTest
139+
static void withListOfStringFields() {
140+
// Test
141+
String soql = SOQL.of(Account.SObjectType)
142+
.with(new List<String>{
143+
'Id',
144+
'Name',
145+
'Industry',
146+
'AccountNumber',
147+
'AnnualRevenue',
148+
'BillingCity'
149+
}).toString();
150+
151+
// Verify
152+
Assert.areEqual('SELECT Id, Name, Industry, AccountNumber, AnnualRevenue, BillingCity FROM Account', soql);
153+
}
154+
138155
@IsTest
139156
static void withStringFields() {
140157
// Test
@@ -1784,6 +1801,18 @@ private class SOQL_Test {
17841801
Assert.areEqual(accounts.size(), result[0].get('names'));
17851802
}
17861803

1804+
@IsTest
1805+
static void toIntegerWithoutCount() {
1806+
// Setup
1807+
List<Account> accounts = insertAccounts();
1808+
1809+
// Test
1810+
Integer result = SOQL.of(Account.SObjectType).toInteger();
1811+
1812+
// Verify
1813+
Assert.areEqual(accounts.size(), result);
1814+
}
1815+
17871816
@IsTest
17881817
static void toInteger() {
17891818
// Setup

website/docs/api/soql.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The following are methods for `SOQL`.
2323
- [`with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4)`](#with-field1---field5)
2424
- [`with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5)`](#with-field1---field5)
2525
- [`with(List<SObjectField> fields)`](#with-fields)
26+
- [`with(List<String> fields)`](#with-fields)
2627
- [`with(String fields)`](#with-string-fields)
2728
- [`with(String relationshipName, SObjectField field)`](#with-related-field1---field5)
2829
- [`with(String relationshipName, SObjectField field1, SObjectField field2)`](#with-related-field1---field5)
@@ -54,8 +55,8 @@ The following are methods for `SOQL`.
5455

5556
- [`whereAre(FilterGroup filterGroup)`](#whereare)
5657
- [`whereAre(Filter filter)`](#whereare)
57-
- [conditionLogic(String order)](#conditionlogic)
58-
- [anyConditionMatching()](#anyconditionmatching);
58+
- [`conditionLogic(String order)`](#conditionlogic)
59+
- [`anyConditionMatching()`](#anyconditionmatching);
5960

6061
[**GROUP BY**](#group-by)
6162

@@ -199,6 +200,7 @@ Use for more than 5 fields.
199200

200201
```apex
201202
SOQL with(List<SObjectField> fields)
203+
SOQL with(List<String> fields)
202204
```
203205

204206
**Example**
@@ -217,6 +219,16 @@ SOQL.of(Account.SObjectType)
217219
Account.AnnualRevenue,
218220
Account.BillingCity
219221
}).toList();
222+
223+
SOQL.of(Account.SObjectType)
224+
.with(new List<String>{
225+
'Id',
226+
'Name',
227+
'Industry',
228+
'AccountNumber',
229+
'AnnualRevenue',
230+
'BillingCity'
231+
}).toList();
220232
```
221233

222234
### with string fields

0 commit comments

Comments
 (0)