Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into feature/query-cursor

Signed-off-by: Piotr PG Gajek <[email protected]>
  • Loading branch information
pgajek2 committed Oct 6, 2024
2 parents f02acdd + 5fc5b87 commit 02d4267
Show file tree
Hide file tree
Showing 12 changed files with 2,463 additions and 389 deletions.
495 changes: 406 additions & 89 deletions force-app/main/default/classes/SOQL.cls

Large diffs are not rendered by default.

811 changes: 713 additions & 98 deletions force-app/main/default/classes/SOQL_Test.cls

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions website/docs/api/soql-filter.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 30
---

# Filter
Expand Down Expand Up @@ -33,13 +33,13 @@ The following are methods for `Filter`.
- [`greaterOrEqual(Object value)`](#greaterorequal)
- [`containsSome(List<String> values)`](#containssome)
- [`contains(String value)`](#contains)
- [`contains(String prefix, String value, String suffix)`](#contains)
- [`notContains(String value)`](#notcontains)
- [`notContains(String prefix, String value, String suffix)`](#notcontains)
- [`endsWith(String value)`](#endswith)
- [`notEndsWith(String value)`](#notendswith)
- [`startsWith(String value)`](#startswith)
- [`notStartsWith(String value)`](#notstartswith)
- [`contains(String prefix, String value, String suffix)`](#contains)
- [`notContains(String prefix, String value, String suffix)`](#notcontains)
- [`isIn(Iterable<Object> iterable)`](#isin)
- [`isIn(List<Object> inList)`](#isin)
- [`isIn(InnerJoin joinQuery)`](#isin-join-query)
Expand Down Expand Up @@ -506,7 +506,7 @@ SOQL.of(Contact.SObjectType)
.toList();
```

### notcontains
### notContains

- `WHERE NOT Name LIKE '%My%'`

Expand Down
2 changes: 1 addition & 1 deletion website/docs/api/soql-filters-group.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 4
sidebar_position: 40
---

# FilterGroup
Expand Down
164 changes: 164 additions & 0 deletions website/docs/api/soql-having-filter-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
sidebar_position: 70
---

# HavingFilterGroup

Create group of having conditions.

```apex
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.City)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
)
.toAggregated();
```


## Methods

The following are methods for `HavingFilterGroup`.

[**ADD CONDITION**](#add-condition)

- [`add(HavingFilterGroup havingFilterGroup)`](#add)
- [`add(HavingFilter havingFilter)`](#add)
- [`add(String dynamicCondition)`](#add)

[**ORDER**](#order)

- [`anyConditionMatching()`](#anyconditionmatching)
- [`conditionLogic(String order)`](#conditionlogic)

## ADD CONDITION
### add

Allows to add multiple conditions.
Add a [`SOQL.HavingFilter`](soql-having-filter.md) or [`SOQL.HavingFilterGroup`](soql-having-filter-group.md) or `String`.

**Signature**

```apex
HavingFilterGroup add(HavingFilterGroup havingFilterGroup)
HavingFilterGroup add(HavingFilter havingFilter)
HavingFilterGroup add(String dynamicCondition)
```

**Example**

```sql
SELECT LeadSource, COUNT(Name)
FROM Lead
GROUP BY LeadSource, City
HAVING (COUNT(Name) > 100 AND City LIKE 'San%')
```

```apex
// build conditions on fly
SOQL.HavingFilterGroup havingFilterGroup = SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'));
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.groupBy(Lead.City)
.have(havingFilterGroup)
.toAggregated();
```

```apex
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.groupBy(Lead.City)
.have(SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
).toAggregated();
```

```apex
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have('(COUNT(Name) > 100 AND COUNT(Name) < 200)')
.have(SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(400))
.add(SOQL.HavingFilter.count(Lead.Name).lessThan(500))
).toAggregated();
```

## ORDER
### conditionLogic

Set conditions order for SOQL query.
When not specify all conditions will be with `AND`.

**Signature**

```apex
HavingFilterGroup conditionLogic(String order)
```

**Example**

```sql
SELECT LeadSource, COUNT(Name)
FROM Lead
GROUP BY LeadSource, City
HAVING (COUNT(Name) > 100 OR City LIKE 'San%')
```
```apex
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.groupBy(Lead.City)
.have(SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
.conditionLogic('1 OR 2')
).toAggregated();
```

### anyConditionMatching

When the [conditionLogic](#conditionlogic) is not specified, all conditions are joined using the `AND` operator by default.

To change the default condition logic, you can utilize the `anyConditionMatching` method, which joins conditions using the `OR` operator.

**Signature**

```apex
HavingFilterGroup anyConditionMatching()
```

**Example**

```sql
SELECT LeadSource, COUNT(Name)
FROM Lead
GROUP BY LeadSource, City
HAVING (COUNT(Name) > 100 OR City LIKE 'San%')
```
```apex
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.groupBy(Lead.City)
.have(SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
.anyConditionMatching()
).toAggregated();
```
Loading

0 comments on commit 02d4267

Please sign in to comment.