Syntax of View Criteria Filter Expressions
You use a view criteria filter expression to identify the specific rows you want to retrieve from a view object.
Each expression includes the case-sensitive name of a queriable field, followed by an operator and one or more operand values (depending on the operator used). Each operand value can be either a literal value or a bind variable value. An attempt to filter on a field that is not queriable or a field name that does not exist in the current object will raise an error. The following are simple examples of filter expressions.
To test whether a value is null
you must use the is
null
or the is not null
keywords:
-
Comment is null
-
Comment is not null
For equality use the =
sign, and for inequality use either the
!=
or the <>
operators. Literal datetime
values must adhere exclusively to the format shown here.
-
NextCallSchedule = '2015-07-15 16:26:30'
-
Priority = 3
-
Priority != 1
-
Priority <> 1
-
ActivityType != 'RS'
-
ActivityType <> 'RS'
For relational comparisons, use the familiar <
,
<=
, >
, or >
operators,
along with between
or not between
. Literal date values
must adhere exclusively the format shown here.
-
CreationDate >= '2015-07-15'
-
Priority <= 2
-
Priority < 3
-
Priority <> 1
-
Priority > 1
-
Priority >= 1
-
TotalLoggedHours >= 12.75
-
Priority between 2 and 4
-
Priority not between 2 and 4
For string matching, you can use the like
operator, employing the
percent sign %
as the wildcard character to obtain "starts with",
"contains", or "ends with" style filtering, depending on where you place your
wildcard(s):
-
RecordName like 'TT-%'
-
RecordName like '%-TT'
-
RecordName like '%-TT-%'
To test whether a field's value is in a list of possibilities, you can use the
in
operator:
-
ActivityType in ('OC','IC','RS')
You can combine expressions using the conjunctions and
and
or
along with matching sets of parentheses for grouping to create
more complex filters like:
-
(Comment is null) or ( (Priority <= 2) and (RecordName like 'TT-99%'))
-
(Comment is not null) and ( (Priority <= 2) or (RecordName like 'TT-99%'))
When using the between
or in
clauses, you must surround
them by parentheses when you join them with other clauses using and
or
or
conjunctions.
You use a filter expression in one of two ways:
-
Append the view criteria filter expression using
appendViewCriteria()
to a view object created usingnewView()
-
Create the view criteria by passing a filter expression to
newViewCriteria()
, then filter a related collection withfindRowsMatchingCriteria()
Filter expressions are not validated at design time, so if your expression contains typographical errors like misspelled field names, incorrect operators, mismatched parentheses, or other errors, you will learn of the problem at runtime when you test your business logic.