🔍WHERE is that subset of records I was looking for?
We learned how to get information from an sObject but we often don't always need or want ALL the records. In most cases we are only interested in records WHERE
certain fields meet some specific conditions we are looking for.
WHERE
clauses are used to filter down the number of records you are interested in, based on those conditions you specify.
It is also worth considering performance here. In our learning environment and with sample datasets, we often don't have thousands of records to retrieve, so fetching the entire object’s records is computationally easier, than say a production environment with perhaps millions of records.
Where was I? Or better yet, WHERE
is Josh Davis?
SELECT Name, MailingStreet FROM Contact WHERE Name = 'Josh Davis'
Name | MailingStreet |
---|---|
Josh Davis | 621 SW 5th Avenue Suite 400 Portland, Oregon 97204 United States |
We use =
to enforce a condition, where the field on the left equals the value on the right. In the case of strings like Name
, we use ’
single quotes to contain what we are looking for.
For our String fields we use the single quotes, but in the case of a number field (Integer, Currency, Decimal etc) we don't need to enclose them with quotes.
SELECT Name, NumberOfEmployees FROM Account WHERE NumberOfEmployees = 100