Skip to main content

JoinQuery

Construct join-query and use it in condition.

of

Conctructs an JoinQuery.

Signature

static JoinQuery of(SObjectType ofObject)

Example

SELECT Id
FROM Account
WHERE Id IN (
SELECT AccountId
FROM Contact
WHERE Name = 'My Contact'
)
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).isIn(
SOQL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
)).toList();

field

SELECT statement that specifies the fields to query.

Signature

static JoinQuery with(SObjectField field)

Example

SELECT Id
FROM Account
WHERE Id IN (
SELECT AccountId
FROM Contact
)
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).isIn(
SOQL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
)).toList();

whereAre

The condition expression in a WHERE clause of a SOQL query includes one or more field expressions. You can specify multiple field expressions in a condition expression by using logical operators.

For more details check SOQL.FilterGroup and SOQL.Filter

Signature

static JoinQuery whereAre(FilterGroup conditions)

Example

SELECT Id
FROM Account
WHERE Id IN (
SELECT AccountId
FROM Contact
WHERE Name = 'My Contact'
)
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).isIn(
SOQL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
.whereAre(SOQL.Filter.with(Contact.Name).equal('My Contact'))
)).toList();