Skip to content

The Soql.InnerQuery Class

Jason Siders edited this page Jul 4, 2025 · 8 revisions

Represents inner query logic, used for filtering results in a WHERE clause. Use this in conjunction with the addWhere SOQL method.

This object uses the Soql.Builder class to allow for flexible query construction. Once your query is built, call toInnerQuery() to build the query as a Soql.InnerQuery object:

SELECT Id
FROM Account
WHERE Id IN (
  SELECT AccountId
  FROM Opportunity
  WHERE IsWon = true
)
Soql.InnerQuery innerQuery = new Soql.InnerQuery(Opportunity.SObjectType)
  ?.addSelect(Opportunity.AccountId)
  ?.addWhere(Opportunity.IsWon, Soql.EQUALS, true)
  ?.toInnerQuery();
Soql soql = Database.Soql.newQuery(Account.SObjectType)
  ?.addWhere(Account.Id, Soql.IN_COLLECTION, innerQuery)
  ?.toSoql();

Constructors

  • InnerQuery(SObjectType objectType)

Methods

This class inherits the Soql.Builder's query building methods, documented here.

Clone this wiki locally