Skip to content

Commit

Permalink
Release v2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajek2 committed Sep 8, 2023
1 parent b8e7d34 commit 2adb46d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions force-app/main/default/classes/SOQL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public virtual inherited sharing class SOQL implements Queryable {
Queryable with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4);
Queryable with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5);
Queryable with(List<SObjectField> fields);
Queryable with(Iterable<String> fields);
Queryable with(String fields);
Queryable with(SObjectField field, String alias);
Queryable with(String relationshipName, SObjectField field);
Expand Down Expand Up @@ -286,6 +287,10 @@ public virtual inherited sharing class SOQL implements Queryable {
return this;
}

public SOQL with(Iterable<String> fields) {
return with(String.join(fields, ','));
}

public SOQL with(String fields) {
builder.fields.with(fields);
return this;
Expand Down Expand Up @@ -525,6 +530,9 @@ public virtual inherited sharing class SOQL implements Queryable {
}

public Integer toInteger() {
if (builder.fields.areCountsEmpty()) {
count();
}
return executor.toInteger(builder.toString(), binder.getBindingMap());
}

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

public Boolean areCountsEmpty() {
return counts.isEmpty();
}

public override String toString() {
if (fields.isEmpty() && counts.isEmpty()) {
return 'SELECT Id';
Expand Down
29 changes: 29 additions & 0 deletions force-app/main/default/classes/SOQL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ private class SOQL_Test {
Assert.areEqual('SELECT Id, Name, Industry, AccountNumber, AnnualRevenue, BillingCity FROM Account', soql);
}

@IsTest
static void withListOfStringFields() {
// Test
String soql = SOQL.of(Account.SObjectType)
.with(new List<String>{
'Id',
'Name',
'Industry',
'AccountNumber',
'AnnualRevenue',
'BillingCity'
}).toString();

// Verify
Assert.areEqual('SELECT Id, Name, Industry, AccountNumber, AnnualRevenue, BillingCity FROM Account', soql);
}

@IsTest
static void withStringFields() {
// Test
Expand Down Expand Up @@ -1784,6 +1801,18 @@ private class SOQL_Test {
Assert.areEqual(accounts.size(), result[0].get('names'));
}

@IsTest
static void toIntegerWithoutCount() {
// Setup
List<Account> accounts = insertAccounts();

// Test
Integer result = SOQL.of(Account.SObjectType).toInteger();

// Verify
Assert.areEqual(accounts.size(), result);
}

@IsTest
static void toInteger() {
// Setup
Expand Down
16 changes: 14 additions & 2 deletions website/docs/api/soql.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The following are methods for `SOQL`.
- [`with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4)`](#with-field1---field5)
- [`with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5)`](#with-field1---field5)
- [`with(List<SObjectField> fields)`](#with-fields)
- [`with(List<String> fields)`](#with-fields)
- [`with(String fields)`](#with-string-fields)
- [`with(String relationshipName, SObjectField field)`](#with-related-field1---field5)
- [`with(String relationshipName, SObjectField field1, SObjectField field2)`](#with-related-field1---field5)
Expand Down Expand Up @@ -54,8 +55,8 @@ The following are methods for `SOQL`.

- [`whereAre(FilterGroup filterGroup)`](#whereare)
- [`whereAre(Filter filter)`](#whereare)
- [conditionLogic(String order)](#conditionlogic)
- [anyConditionMatching()](#anyconditionmatching);
- [`conditionLogic(String order)`](#conditionlogic)
- [`anyConditionMatching()`](#anyconditionmatching);

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

Expand Down Expand Up @@ -199,6 +200,7 @@ Use for more than 5 fields.

```apex
SOQL with(List<SObjectField> fields)
SOQL with(List<String> fields)
```

**Example**
Expand All @@ -217,6 +219,16 @@ SOQL.of(Account.SObjectType)
Account.AnnualRevenue,
Account.BillingCity
}).toList();
SOQL.of(Account.SObjectType)
.with(new List<String>{
'Id',
'Name',
'Industry',
'AccountNumber',
'AnnualRevenue',
'BillingCity'
}).toList();
```

### with string fields
Expand Down

0 comments on commit 2adb46d

Please sign in to comment.