WHERE & HAVING
Structure
The where
and having
clauses use the following format:
WHERE: = [ CONDITION | ('AND'|'OR') | WHERE ],
CONDITION: = {field, op, val} | {field, op, subqry}
//...
where: [
{ field: f.select('name'), op: '=', val: 'acme' },
{ field: f.select('annualRevenue'), op: '>=', val: 100 }
]
WHERE Name = 'acme' AND AnnualRevenue >= 100
where: [
{ field: f.select('name'), op: '=', val: 'acme' },
'OR',
{ field: f.select('annualRevenue'), op: '>=', val: 100 }
]
WHERE Name = 'acme' OR AnnualRevenue >= 100
putting
AND
between conditions is optional. If left out, it will be implied (but may be included for readability)If
op
is omitted, it defaults to either=
orIN
depending on theval
typenothing prevents multiple LogicalConditions (
AND|OR
) from occurring back to back. If this happens, the last condition will be used
Nesting Conditions
Conditions can be grouped/nested in parentheses by starting a new array
where: [
{ field: f.select('name'), op: '=', val: 'acme' },
'AND',
[
{ field: f.select('annualRevenue'), op: '>=', val: 100 },
'OR',
{ field: f.select('active'), op: '=', val: true }
]
]
WHERE Name = 'acme'
AND (AnnualRevenue >= 100 OR Active__c = true)
where: [
[
{ field: f.select('name'), op: '=', val: 'acme' },
'OR',
{ field: f.select('name'), op: '=', val: 'stark' },
],
'AND',
[
{ field: f.select('annualRevenue'), op: '>=', val: 100 },
'OR',
{ field: f.select('active'), op: '=', val: true }
]
]
WHERE
(Name = 'acme' OR Name = 'stark')
AND
(AnnualRevenue >= 100 OR Active__c = true)
where: [
{ field: f.select('name'), op: '=', val: 'acme' },
'OR',
[
{ field: f.select('annualRevenue'), op: '>=', val: 100 },
'AND',
[
{ field: f.select('active'), op: '=', val: true },
'OR',
{ field: f.select('accountSource'), op: '=', val: 'web' }
]
]
]
WHERE
Name = 'acme'
OR (
AnnualRevenue >= 100
AND (
Active__c = true
OR AccountSource = 'web'
)
)
Value Rendering
Condition values are automatically converted based on their type:
string
string
{ field: f.select('name'), op: '=', val: 'acme' }
//-> Name = 'acme'
string[]
string[]
{ field: f.select('name'), op: 'IN', val: ['acme', 'stark'] }
//-> Name IN ('acme', 'stark')
number
number
{ field: f.select('annualRevenue'), op: '>', val: 100 }
//-> AnnualRevenue > 100
boolean
boolean
{ field: f.select('active'), op: '=', val: false }
//-> Active__c = false
Date
Date
{ field: f.select('createdDate'), op: '<', val: new Date() }
//-> CreatedDate < 2020-12-23T02:44:49z
Last updated
Was this helpful?