Query syntax of custom object records
You can use the Query custom object records API call to query custom object records. You can define your query through the q
query parameter of this operation.
See the following query syntax for the q
parameter.
Simple Query
Field Existence
Check existence of a field by querying with _exists_:[FieldName]
.
-
Search for custom fields data where the
title
field has non-null value (the field exists and the value of it is not null)._exists_:title
Field Equality
Check whether the value of a field equals to a certain value by querying with [FieldName]:[ExpectedValue]
-
Search for custom fields data with field
status
isactive
.status:active
-
Search for custom fields data with field
author
identical to phrase"john smith"
.author:"John Smith"
Ranges
Ranges can be specified for date and numeric fields. See the following statement syntax:
-
Less than:
[FieldName]:<[Upperbound]
-
Less than or equal to:
[FieldName]:<=[Upperbound]
-
Greater than:
[FieldName]:>[Lowerbound]
-
Greater than or equal to:
[FieldName]:>=[Lowerbound]
Number
-
Search for custom fields data with field
age
less than5
.age:<5
Date
When you query with ranges for date fields, you must use the \
(backslash) as an escape character for every colon (\:
) in the date bounds as colon (:
) is an operator in the query syntax.
-
Search for custom fields data with field
activeDate
less than2018-01-01T00:00:00.001Z
.activeDate:<2018-01-01T00\:00\:00.001Z
-
Search for custom fields data with field
activeDate
less than2018-01-01T00:00:00Z
.activeDate:<2018-01-01T00\:00\:00Z
-
Search for custom fields data with field
activeDate
less than2018-01-01T00:00:00-08:00
.activeDate:<2018-01-01T00\:00\:00-08\:00
-
Search for custom fields data with field
activeDate
less than2018-01-01
.activeDate:<2018-01-01
-
Search for custom fields data with field
activeDate
less than2018-01
(same as2018-01-01
).activeDate:<2018-01
-
Search for custom fields data with field
activeDate
less than2018
(same as2018-01-01
).activeDate:<2018
-
Search for custom fields data with field
activeDate
less than1514764800000
(2018-01-01
in milliseconds).activeDate:<1514764800000
Note:
-
Range query by a number on a date field compares field values as a timestamp in milliseconds except that the number is a 4-digit number. In that case, the field values will be considered as the value of a year.
-
activeDate:<1
will return custom fields data withactiveDate
less than1970-01-01T00:00:00.001Z (0000000000001)
. -
activeDate:<2001
will return custom fields data withactiveDate
less than2001-01-01
.
-
-
Range query by date only (without time) on date field with full date (with time) compares only their date part.
activeDate:>2018
will not return custom fields data withactiveDate
has value2018-01-01T23:59:59Z
since their dates are equal. But it will return custom fields data withactiveDate
is2018-01-02
.
-
Range query by year only works the same as by the first day of that year. Range query by year-month works the same as by the first day of the month.
-
activeDate:>2018
works the same asactiveDate:>2018-01-01
. -
activeDate:>2018-05
works the same asactiveDate:>2018-05-01
.
-
-
Range query by full date (with time) on date field with date only (without time) will assume the time of the date field is
00:00:00.000Z
.activeDate:<2018-01-01T00\:00\:00.001Z
will return custom fields data withactiveDate
value as2018-01-01
.
Complex Query Using Boolean Operators
Custom object query currently supports the AND (&&)
, OR (||)
and NOT (!)
operators. Note that the operators are case-sensitive. You must use uppercase.
AND
-
Search for custom fields data whose
status
isactive
andactiveDate
is less than2018
.status:active AND activeDate:<2018
or
status:active && activeDate:<2018
OR
-
Search for custom fields data whose
status
isactive
oractiveDate
is less than2018
.status:active OR activeDate:<2018
or
status:active || activeDate:<2018
NOT
-
Search for custom fields data whose
status
is missing orstatus
has a null value.!_exists_:status
or
NOT _exists_:status
-
Search for custom fields data whose
status
is notactive
(status
is either missing or null).!status:active
or
NOT status:active
Note: To search for custom fields data where
status
exists and its value not equal toactive
, use_exists_:status AND !status:active
. -
Search for custom fields data with field
activeDate
no less than2018
(includingactiveDate
is missing or null).!activeDate:<2018
or
NOT activeDate:<2018
Note: To search for custom fields data where
activeDate
exists and its value is no less than2018
, use_exists_:activeDate AND !activeDate:<2018
.
Deal with the null value
The null value fields cannot be distinguished from the missing fields. Therefore, when querying by the existence of a field, it only returns the records that contain the field and the field value is not null. Query by the non-existence of one field will return the records that either miss this field or have a null value in this field.