diff --git a/example-app/ExampleFactory.cls-meta.xml b/example-app/ExampleFactory.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/ExampleFactory.cls-meta.xml
+++ b/example-app/ExampleFactory.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/example-app/ExampleRepoFactory.cls-meta.xml b/example-app/ExampleRepoFactory.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/ExampleRepoFactory.cls-meta.xml
+++ b/example-app/ExampleRepoFactory.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/example-app/handlers/AccountHandler.cls-meta.xml b/example-app/handlers/AccountHandler.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/handlers/AccountHandler.cls-meta.xml
+++ b/example-app/handlers/AccountHandler.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/example-app/handlers/AccountHandlerTests.cls-meta.xml b/example-app/handlers/AccountHandlerTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/handlers/AccountHandlerTests.cls-meta.xml
+++ b/example-app/handlers/AccountHandlerTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/example-app/handlers/ExampleSObjectTest.cls-meta.xml b/example-app/handlers/ExampleSObjectTest.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/handlers/ExampleSObjectTest.cls-meta.xml
+++ b/example-app/handlers/ExampleSObjectTest.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/example-app/triggers/TriggerHandler.cls-meta.xml b/example-app/triggers/TriggerHandler.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/triggers/TriggerHandler.cls-meta.xml
+++ b/example-app/triggers/TriggerHandler.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/example-app/triggers/TriggerHandler_Tests.cls-meta.xml b/example-app/triggers/TriggerHandler_Tests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/example-app/triggers/TriggerHandler_Tests.cls-meta.xml
+++ b/example-app/triggers/TriggerHandler_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/dml/DML.cls-meta.xml b/force-app/dml/DML.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/dml/DML.cls-meta.xml
+++ b/force-app/dml/DML.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/dml/DMLMock.cls-meta.xml b/force-app/dml/DMLMock.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/dml/DMLMock.cls-meta.xml
+++ b/force-app/dml/DMLMock.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/dml/DMLTests.cls-meta.xml b/force-app/dml/DMLTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/dml/DMLTests.cls-meta.xml
+++ b/force-app/dml/DMLTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/dml/IDML.cls-meta.xml b/force-app/dml/IDML.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/dml/IDML.cls-meta.xml
+++ b/force-app/dml/IDML.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/factory/Factory.cls-meta.xml b/force-app/factory/Factory.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/factory/Factory.cls-meta.xml
+++ b/force-app/factory/Factory.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/factory/RepoFactory.cls-meta.xml b/force-app/factory/RepoFactory.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/factory/RepoFactory.cls-meta.xml
+++ b/force-app/factory/RepoFactory.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/factory/RepoFactoryMock.cls-meta.xml b/force-app/factory/RepoFactoryMock.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/factory/RepoFactoryMock.cls-meta.xml
+++ b/force-app/factory/RepoFactoryMock.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/AggregateRecord.cls-meta.xml b/force-app/repository/AggregateRecord.cls-meta.xml
index 7a51829..f5e18fd 100644
--- a/force-app/repository/AggregateRecord.cls-meta.xml
+++ b/force-app/repository/AggregateRecord.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
diff --git a/force-app/repository/AggregateRepository.cls-meta.xml b/force-app/repository/AggregateRepository.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/AggregateRepository.cls-meta.xml
+++ b/force-app/repository/AggregateRepository.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/AggregateRepositoryTests.cls-meta.xml b/force-app/repository/AggregateRepositoryTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/AggregateRepositoryTests.cls-meta.xml
+++ b/force-app/repository/AggregateRepositoryTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/Aggregation.cls-meta.xml b/force-app/repository/Aggregation.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/Aggregation.cls-meta.xml
+++ b/force-app/repository/Aggregation.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/AggregationTests.cls-meta.xml b/force-app/repository/AggregationTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/AggregationTests.cls-meta.xml
+++ b/force-app/repository/AggregationTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/DateFunction.cls-meta.xml b/force-app/repository/DateFunction.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/DateFunction.cls-meta.xml
+++ b/force-app/repository/DateFunction.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/FieldLevelHistory.cls-meta.xml b/force-app/repository/FieldLevelHistory.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/FieldLevelHistory.cls-meta.xml
+++ b/force-app/repository/FieldLevelHistory.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/FieldLevelHistoryRepo.cls-meta.xml b/force-app/repository/FieldLevelHistoryRepo.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/FieldLevelHistoryRepo.cls-meta.xml
+++ b/force-app/repository/FieldLevelHistoryRepo.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/FieldLevelHistoryRepoTests.cls-meta.xml b/force-app/repository/FieldLevelHistoryRepoTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/FieldLevelHistoryRepoTests.cls-meta.xml
+++ b/force-app/repository/FieldLevelHistoryRepoTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/IAggregateRepository.cls-meta.xml b/force-app/repository/IAggregateRepository.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/IAggregateRepository.cls-meta.xml
+++ b/force-app/repository/IAggregateRepository.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/IHistoryRepository.cls-meta.xml b/force-app/repository/IHistoryRepository.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/IHistoryRepository.cls-meta.xml
+++ b/force-app/repository/IHistoryRepository.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/IRepository.cls-meta.xml b/force-app/repository/IRepository.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/IRepository.cls-meta.xml
+++ b/force-app/repository/IRepository.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/Query.cls b/force-app/repository/Query.cls
index 4c9d1e9..c37177b 100644
--- a/force-app/repository/Query.cls
+++ b/force-app/repository/Query.cls
@@ -29,6 +29,19 @@ public virtual class Query {
return new ParentQuery(parentFields, this);
}
+ public static Query subquery(Schema.SObjectField field, Schema.SObjectField innerMatchingField, Query subcondition) {
+ return subquery(field, innerMatchingField.getDescribe().getSObjectType(), innerMatchingField, subcondition);
+ }
+
+ public static Query subquery(
+ Schema.SObjectField field,
+ Schema.SObjectType objectType,
+ Schema.SObjectField innerMatchingField,
+ Query subcondition
+ ) {
+ return new SubQuery(field, objectType, innerMatchingField, subcondition);
+ }
+
public static Query equals(SObjectField field, Object predicate) {
return new Query(field, Operator.EQUALS, predicate);
}
@@ -80,6 +93,37 @@ public virtual class Query {
return new AndQuery(innerQueries);
}
+ private class SubQuery extends Query {
+ private final Schema.SObjectField field;
+ private final Schema.SObjectType objectType;
+ private final Schema.SObjectField innerMatchingField;
+ private final Query subcondition;
+
+ public SubQuery(
+ Schema.SObjectField field,
+ Schema.SObjectType objectType,
+ Schema.SObjectField innerMatchingField,
+ Query subcondition
+ ) {
+ this.field = field;
+ this.objectType = objectType;
+ this.innerMatchingField = innerMatchingField;
+ this.subcondition = subcondition;
+ }
+
+ public override String toString() {
+ String whereClause = ' WHERE ' + this.subcondition.toString();
+ this.bindVars.putAll(this.subcondition.getBindVars());
+ return this.field.getDescribe().getName() +
+ ' IN (SELECT ' +
+ this.innerMatchingField +
+ ' FROM ' +
+ this.objectType +
+ whereClause +
+ ')';
+ }
+ }
+
private abstract class DelimitedQuery extends Query {
private final List queries;
diff --git a/force-app/repository/Query.cls-meta.xml b/force-app/repository/Query.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/Query.cls-meta.xml
+++ b/force-app/repository/Query.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/QueryTests.cls b/force-app/repository/QueryTests.cls
index 35752ed..1689996 100644
--- a/force-app/repository/QueryTests.cls
+++ b/force-app/repository/QueryTests.cls
@@ -163,4 +163,26 @@ private class QueryTests {
System.assertEquals('AccountId != :bindVar0', notEquals.toString());
System.assertEquals(new Set(), notEquals.getBindVars().get('bindVar0'));
}
+
+ @IsTest
+ static void it_allows_subqueries() {
+ Query subquery = Query.subquery(
+ Contact.AccountId,
+ Account.Id,
+ Query.andQuery(
+ new List{
+ Query.equals(Account.AnnualRevenue, 50),
+ Query.equals(Account.Industry, 'Tech'),
+ Query.orQuery(
+ new List{ Query.equals(Account.NumberOfEmployees, 1), Query.equals(Account.Site, 'web3') }
+ )
+ }
+ )
+ );
+
+ Assert.areEqual(
+ 'AccountId IN (SELECT Id FROM Account WHERE (AnnualRevenue = :bindVar0 AND Industry = :bindVar1 AND (NumberOfEmployees = :bindVar2 OR Site = :bindVar3)))',
+ subquery.toString()
+ );
+ }
}
diff --git a/force-app/repository/QueryTests.cls-meta.xml b/force-app/repository/QueryTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/QueryTests.cls-meta.xml
+++ b/force-app/repository/QueryTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/Repository.cls-meta.xml b/force-app/repository/Repository.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/Repository.cls-meta.xml
+++ b/force-app/repository/Repository.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/RepositorySortOrder.cls-meta.xml b/force-app/repository/RepositorySortOrder.cls-meta.xml
index 9bbf7b4..3a10d2e 100644
--- a/force-app/repository/RepositorySortOrder.cls-meta.xml
+++ b/force-app/repository/RepositorySortOrder.cls-meta.xml
@@ -1,5 +1,5 @@
- 56.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/repository/RepositoryTests.cls-meta.xml b/force-app/repository/RepositoryTests.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/repository/RepositoryTests.cls-meta.xml
+++ b/force-app/repository/RepositoryTests.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file
diff --git a/force-app/utils/TestingUtils.cls-meta.xml b/force-app/utils/TestingUtils.cls-meta.xml
index 642d054..3a10d2e 100644
--- a/force-app/utils/TestingUtils.cls-meta.xml
+++ b/force-app/utils/TestingUtils.cls-meta.xml
@@ -1,5 +1,5 @@
- 58.0
+ 60.0
Active
\ No newline at end of file