Intro to SOQLReading Only
Ready to play fetch!? ๐ No sticks here, just data!
To get information stored within Salesforce's database, we use the Salesforce Object Query Language, or SOQL, to help us retrieve information from the system. SOQL, pronounced as "sock-el" or "soak-el," is the query language for reading/retrieving information from Salesforce's database.
SOQL can be embedded directly within Apex code, allowing developers to retrieve data programmatically. These queries can be hardcoded or built dynamically in Apex. It can also be written and executed outside of Apex, which we'll get to in the next lesson.
You can SELECT
fields FROM
an sObject to retrieve it's data.
All SOQL queries will contain at least two keywords, SELECT
and FROM
, along with their associated information. The SELECT
keyword represents the fields you want to display, while the FROM
defines which sObject you want to get those fields from.
As an example, to get every Account record's Id, you would issue this SOQL:
SELECT Id FROM Account
You'd get back this data:
Id |
---|
001ak000004N8NQAA0 |
001ak000004N8NRAA0 |
001ak000004N8NSAA0 |
... |
Even with all this power, you are still bound by the rules of Salesforceโs security model. You cannot query any object, field, or record you have not been explicitly granted access to. More on that here.
Now, it is common to use a number of other keywords, which we will cover in detail, but this is a great start.
This specific course will introduce you to SOQL but it will not cover how to implement SOQL in Apex. If you know this content you're 90% of the way there. We'll cover SOQL in Apex in a different course.