Skip to content

Commit 87cd0c0

Browse files
authored
Having [In Progress] (#129)
* Having draft Signed-off-by: Piotr PG Gajek <[email protected]> * Having Interfaces Signed-off-by: Piotr PG Gajek <[email protected]> * having builder Signed-off-by: Piotr PG Gajek <[email protected]> * adapters Signed-off-by: Piotr PG Gajek <[email protected]> * Having Unit Tests Signed-off-by: Piotr PG Gajek <[email protected]> * Having Unit Tests Signed-off-by: Piotr PG Gajek <[email protected]> * Code refactoring Signed-off-by: Piotr PG Gajek <[email protected]> * SOQL Having Documentation Signed-off-by: Piotr PG Gajek <[email protected]> --------- Signed-off-by: Piotr PG Gajek <[email protected]>
1 parent 1e2a8f5 commit 87cd0c0

File tree

12 files changed

+2455
-335
lines changed

12 files changed

+2455
-335
lines changed

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

Lines changed: 408 additions & 78 deletions
Large diffs are not rendered by default.

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

Lines changed: 703 additions & 55 deletions
Large diffs are not rendered by default.

website/docs/api/soql-filter.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 3
2+
sidebar_position: 30
33
---
44

55
# Filter
@@ -33,13 +33,13 @@ The following are methods for `Filter`.
3333
- [`greaterOrEqual(Object value)`](#greaterorequal)
3434
- [`containsSome(List<String> values)`](#containssome)
3535
- [`contains(String value)`](#contains)
36+
- [`contains(String prefix, String value, String suffix)`](#contains)
3637
- [`notContains(String value)`](#notcontains)
38+
- [`notContains(String prefix, String value, String suffix)`](#notcontains)
3739
- [`endsWith(String value)`](#endswith)
3840
- [`notEndsWith(String value)`](#notendswith)
3941
- [`startsWith(String value)`](#startswith)
4042
- [`notStartsWith(String value)`](#notstartswith)
41-
- [`contains(String prefix, String value, String suffix)`](#contains)
42-
- [`notContains(String prefix, String value, String suffix)`](#notcontains)
4343
- [`isIn(Iterable<Object> iterable)`](#isin)
4444
- [`isIn(List<Object> inList)`](#isin)
4545
- [`isIn(InnerJoin joinQuery)`](#isin-join-query)
@@ -506,7 +506,7 @@ SOQL.of(Contact.SObjectType)
506506
.toList();
507507
```
508508

509-
### notcontains
509+
### notContains
510510

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

website/docs/api/soql-filters-group.md

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

55
# FilterGroup
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
sidebar_position: 70
3+
---
4+
5+
# HavingFilterGroup
6+
7+
Create group of having conditions.
8+
9+
```apex
10+
SOQL.of(Lead.SObjectType)
11+
.with(Lead.LeadSource)
12+
.count(Lead.Name)
13+
.groupBy(Lead.City)
14+
.groupBy(Lead.LeadSource)
15+
.have(SOQL.HavingFilterGroup
16+
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
17+
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
18+
)
19+
.toAggregated();
20+
```
21+
22+
23+
## Methods
24+
25+
The following are methods for `HavingFilterGroup`.
26+
27+
[**ADD CONDITION**](#add-condition)
28+
29+
- [`add(HavingFilterGroup havingFilterGroup)`](#add)
30+
- [`add(HavingFilter havingFilter)`](#add)
31+
- [`add(String dynamicCondition)`](#add)
32+
33+
[**ORDER**](#order)
34+
35+
- [`anyConditionMatching()`](#anyconditionmatching)
36+
- [`conditionLogic(String order)`](#conditionlogic)
37+
38+
## ADD CONDITION
39+
### add
40+
41+
Allows to add multiple conditions.
42+
Add a [`SOQL.HavingFilter`](soql-having-filter.md) or [`SOQL.HavingFilterGroup`](soql-having-filter-group.md) or `String`.
43+
44+
**Signature**
45+
46+
```apex
47+
HavingFilterGroup add(HavingFilterGroup havingFilterGroup)
48+
HavingFilterGroup add(HavingFilter havingFilter)
49+
HavingFilterGroup add(String dynamicCondition)
50+
```
51+
52+
**Example**
53+
54+
```sql
55+
SELECT LeadSource, COUNT(Name)
56+
FROM Lead
57+
GROUP BY LeadSource, City
58+
HAVING (COUNT(Name) > 100 AND City LIKE 'San%')
59+
```
60+
61+
```apex
62+
// build conditions on fly
63+
SOQL.HavingFilterGroup havingFilterGroup = SOQL.HavingFilterGroup
64+
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
65+
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'));
66+
67+
SOQL.of(Lead.SObjectType)
68+
.with(Lead.LeadSource)
69+
.count(Lead.Name)
70+
.groupBy(Lead.LeadSource)
71+
.groupBy(Lead.City)
72+
.have(havingFilterGroup)
73+
.toAggregated();
74+
```
75+
76+
```apex
77+
SOQL.of(Lead.SObjectType)
78+
.with(Lead.LeadSource)
79+
.count(Lead.Name)
80+
.groupBy(Lead.LeadSource)
81+
.groupBy(Lead.City)
82+
.have(SOQL.HavingFilterGroup
83+
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
84+
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
85+
).toAggregated();
86+
```
87+
88+
```apex
89+
SOQL.of(Lead.SObjectType)
90+
.with(Lead.LeadSource)
91+
.count(Lead.Name)
92+
.groupBy(Lead.LeadSource)
93+
.have('(COUNT(Name) > 100 AND COUNT(Name) < 200)')
94+
.have(SOQL.HavingFilterGroup
95+
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(400))
96+
.add(SOQL.HavingFilter.count(Lead.Name).lessThan(500))
97+
).toAggregated();
98+
```
99+
100+
## ORDER
101+
### conditionLogic
102+
103+
Set conditions order for SOQL query.
104+
When not specify all conditions will be with `AND`.
105+
106+
**Signature**
107+
108+
```apex
109+
HavingFilterGroup conditionLogic(String order)
110+
```
111+
112+
**Example**
113+
114+
```sql
115+
SELECT LeadSource, COUNT(Name)
116+
FROM Lead
117+
GROUP BY LeadSource, City
118+
HAVING (COUNT(Name) > 100 OR City LIKE 'San%')
119+
```
120+
```apex
121+
SOQL.of(Lead.SObjectType)
122+
.with(Lead.LeadSource)
123+
.count(Lead.Name)
124+
.groupBy(Lead.LeadSource)
125+
.groupBy(Lead.City)
126+
.have(SOQL.HavingFilterGroup
127+
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
128+
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
129+
.conditionLogic('1 OR 2')
130+
).toAggregated();
131+
```
132+
133+
### anyConditionMatching
134+
135+
When the [conditionLogic](#conditionlogic) is not specified, all conditions are joined using the `AND` operator by default.
136+
137+
To change the default condition logic, you can utilize the `anyConditionMatching` method, which joins conditions using the `OR` operator.
138+
139+
**Signature**
140+
141+
```apex
142+
HavingFilterGroup anyConditionMatching()
143+
```
144+
145+
**Example**
146+
147+
```sql
148+
SELECT LeadSource, COUNT(Name)
149+
FROM Lead
150+
GROUP BY LeadSource, City
151+
HAVING (COUNT(Name) > 100 OR City LIKE 'San%')
152+
```
153+
```apex
154+
SOQL.of(Lead.SObjectType)
155+
.with(Lead.LeadSource)
156+
.count(Lead.Name)
157+
.groupBy(Lead.LeadSource)
158+
.groupBy(Lead.City)
159+
.have(SOQL.HavingFilterGroup
160+
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
161+
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
162+
.anyConditionMatching()
163+
).toAggregated();
164+
```

0 commit comments

Comments
 (0)