Newer Version Available

This content describes an older version of this product. View Latest

SOQL with Big Objects

You can query the fields in a big object’s index using a subset of standard SOQL commands.

Build an index query starting from the first field defined in the index, without gaps between the first and last field in the query. You can use = or IN on any field in your query, although you can use IN only one time. You can use the range operations <, >, <=, or >= only on the last field of your query.

The IN clause with only one argument, such as FirstName IN('Charlie'), is equivalent to using =, such as FirstName='Charlie'. For clarity, we suggest you use the = form in this case.

Tip

You can include the system fields CreatedById, CreatedDate, and SystemModstamp in queries.

To guarantee the order of the query results, use the ORDER BY clause.

The following queries assume that you have a table in which the index is defined by LastName__c, FirstName__c, and PhoneNumber__c.

This query specifies all three fields in the index. In this case, the filter on PhoneNumber__c can use a range operator.

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c='Kelly' AND FirstName__c='Charlie' AND PhoneNumber__c='2155555555'

This query specifies only the first two fields in the index. In this case, the filter on FirstName__c can use a range operator.

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c='Kelly' AND FirstName__c='Charlie'

This query specifies only the first field in the index. The filter on LastName__c can use a range operator.

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c='Kelly'

This query uses the IN operator on the first field in the index.

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c IN ('Kelly','Jones','Capulet','Montague') AND FirstName__c='Charlie'

This query doesn’t work because of a gap in the query where FirstName__c is required.

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c='Kelly' AND PhoneNumber__c='2155555555'
This query also doesn’t work because it uses the IN operator twice.
1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c IN ('Kelly','Jones') AND FirstName__c IN ('Charlie','Lisa')

This query works, even though it appears to have two IN operators in the WHERE clause. But because the second IN has only one argument, it’s equivalent to an Equals operator and is thus allowed.

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c IN ('Kelly','Jones') AND FirstName__c IN ('Charlie')

For clarity, we suggest you rewrite the preceding SOQL statement like this:

1SELECT LastName__c, FirstName__c, PhoneNumber__c
2FROM Phone_Book__b
3WHERE LastName__c IN ('Kelly','Jones') AND FirstName__c='Charlie'

SOQL Operations Not Allowed with Big Objects

  • When building an index query, don’t leave gaps between the first and last field in the query.
  • The !=, LIKE, NOT IN, EXCLUDES, and INCLUDES operators aren’t valid in any query.
  • Aggregate functions aren’t valid in any query.
  • To retrieve a list of results, don’t use the Id field in a query. Including Id in a query returns only results that have an empty ID (000000000000000 or 000000000000000AAA).

    When you use Developer Console to generate a query from a resource, the Id field is included automatically. To query big objects in Developer Console, remove Id from the generated query.

    Note

To perform operations not allowed with SOQL, use Async SOQL instead.