Skip to content

Commit 07116cf

Browse files
pgajek20ptaq0
andauthored
includes and excludes (#49)
* includes and excludes * refactoring * enable acr in scratch * added scratch org support for ACR and person accounts --------- Co-authored-by: Maciej Ptak <[email protected]>
1 parent 1de6eef commit 07116cf

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

config/project-scratch-def.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
{
22
"orgName": "Beyond The Cloud Dev",
33
"edition": "Developer",
4-
"features": ["EnableSetPasswordInApi"],
4+
"features": [
5+
"EnableSetPasswordInApi",
6+
"ContactsToMultipleAccounts",
7+
"PersonAccounts"
8+
],
59
"settings": {
610
"lightningExperienceSettings": {
711
"enableS1DesktopEnabled": true
812
},
913
"mobileSettings": {
1014
"enableS1EncryptedStoragePref2": false
15+
},
16+
"accountSettings": {
17+
"enableRelateContactToMultipleAccounts": true
1118
}
1219
}
1320
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ public inherited sharing class SOQL implements Queryable {
190190
Filter notIn(Iterable<Object> iterable); // NOT IN :inList or inSet
191191
Filter notIn(List<Object> inList); // NOT IN :inList
192192
Filter notIn(InnerJoin joinQuery); // SOQL.InnerJoin
193+
Filter includesAll(Iterable<String> values); // join with ;
194+
Filter includesSome(Iterable<String> values); // join with ,
195+
Filter excludesAll(Iterable<String> values); // join with ,
196+
Filter excludesSome(Iterable<String> values); // join with ;
193197

194198
Filter removeWhenNull(); // Condition will be removed for value = null
195199

@@ -1114,6 +1118,30 @@ public inherited sharing class SOQL implements Queryable {
11141118
return set('NOT IN', joinQuery);
11151119
}
11161120

1121+
public Filter includesAll(Iterable<String> iterable) {
1122+
//Bind expressions can't be used with other clauses, such as INCLUDES.
1123+
skipBinding = true;
1124+
return set('INCLUDES', '(\'' + String.join(iterable, ';') + '\')');
1125+
}
1126+
1127+
public Filter includesSome(Iterable<String> iterable) {
1128+
//Bind expressions can't be used with other clauses, such as INCLUDES.
1129+
skipBinding = true;
1130+
return set('INCLUDES', '(\'' + String.join(iterable, '\', \'') + '\')');
1131+
}
1132+
1133+
public Filter excludesAll(Iterable<String> iterable) {
1134+
//Bind expressions can't be used with other clauses, such as EXCLUDES.
1135+
skipBinding = true;
1136+
return set('EXCLUDES', '(\'' + String.join(iterable, '\', \'') + '\')');
1137+
}
1138+
1139+
public Filter excludesSome(Iterable<String> iterable) {
1140+
//Bind expressions can't be used with other clauses, such as EXCLUDES.
1141+
skipBinding = true;
1142+
return set('EXCLUDES', '(\'' + String.join(iterable, ';') + '\')');
1143+
}
1144+
11171145
private Filter set(String comperator, Object value) {
11181146
this.value = value;
11191147
this.comperator = comperator;

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,66 @@ private class SOQL_Test {
783783
Assert.areEqual(names, binding.get('v1'));
784784
}
785785

786+
@IsTest
787+
static void inlcudesAll() {
788+
// Setup
789+
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };
790+
791+
// Test
792+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
793+
.with(AccountContactRelation.Id)
794+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).includesAll(roles));
795+
796+
// Verify
797+
String soql = builder.toString();
798+
Assert.areEqual('SELECT Id FROM AccountContactRelation WHERE Roles INCLUDES (\'Business User;Decision Maker\')', soql);
799+
}
800+
801+
@IsTest
802+
static void inlcudesSome() {
803+
// Setup
804+
List<String> roles = new List<String>{ 'Executive Sponsor', 'Economic Decision Maker' };
805+
806+
// Test
807+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
808+
.with(AccountContactRelation.Id)
809+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).includesSome(roles));
810+
811+
// Verify
812+
String soql = builder.toString();
813+
Assert.areEqual('SELECT Id FROM AccountContactRelation WHERE Roles INCLUDES (\'Executive Sponsor\', \'Economic Decision Maker\')', soql);
814+
}
815+
816+
@IsTest
817+
static void excludesAll() {
818+
// Setup
819+
List<String> roles = new List<String>{ 'Technical Buyer', 'Economic Buyer' };
820+
821+
// Test
822+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
823+
.with(AccountContactRelation.Id)
824+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).excludesAll(roles));
825+
826+
// Verify
827+
String soql = builder.toString();
828+
Assert.areEqual('SELECT Id FROM AccountContactRelation WHERE Roles EXCLUDES (\'Technical Buyer\', \'Economic Buyer\')', soql);
829+
}
830+
831+
@IsTest
832+
static void excludesSome() {
833+
// Setup
834+
List<String> roles = new List<String>{ 'Evaluator', 'Influencer' };
835+
836+
// Test
837+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
838+
.with(AccountContactRelation.Id)
839+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).excludesSome(roles));
840+
841+
// Verify
842+
String soql = builder.toString();
843+
Assert.areEqual('SELECT Id FROM AccountContactRelation WHERE Roles EXCLUDES (\'Evaluator;Influencer\')', soql);
844+
}
845+
786846
@IsTest
787847
static void isNull() {
788848
// Test

website/docs/api/soql-filter.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,68 @@ SOQL.of(Contact.SObjectType)
587587
)).toList();
588588
```
589589

590+
## multi-select picklist
591+
592+
### includesAll
593+
594+
```sql
595+
SELECT Id
596+
FROM AccountContactRelation
597+
WHERE Roles INCLUDES ('Business User;Decision Maker')
598+
```
599+
```apex
600+
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };
601+
602+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
603+
.with(AccountContactRelation.Id)
604+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).includesAll(roles));
605+
```
606+
607+
### includesSome
608+
609+
```sql
610+
SELECT Id
611+
FROM AccountContactRelation
612+
WHERE Roles INCLUDES ('Business User', 'Decision Maker')
613+
```
614+
```apex
615+
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };
616+
617+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
618+
.with(AccountContactRelation.Id)
619+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).includesSome(roles));
620+
```
621+
622+
### excludesAll
623+
624+
```sql
625+
SELECT Id
626+
FROM AccountContactRelation
627+
WHERE Roles EXCLUDES ('Business User', 'Decision Maker')
628+
```
629+
```apex
630+
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };
631+
632+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
633+
.with(AccountContactRelation.Id)
634+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).excludesAll(roles));
635+
```
636+
637+
### excludesSome
638+
639+
```sql
640+
SELECT Id
641+
FROM AccountContactRelation
642+
WHERE Roles EXCLUDES ('Business User;Decision Maker')
643+
```
644+
```apex
645+
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };
646+
647+
SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
648+
.with(AccountContactRelation.Id)
649+
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).excludesSome(roles));
650+
```
651+
590652
## additional
591653

592654
### removeWhenNull

0 commit comments

Comments
 (0)