Salesforce is a place where a lot of data is placed. In general, we have some Different languages to communicate with databases like SQL and MongoDB, but to communicate with the data in Salesforce what we use is SOQL.
What is SOQL
Salesforce Object Query Language is a language that is used to retrieve the data from the Salesforce. Fetching data within Salesforce using SOQL is much simpler than fetching data from other databases using the above-mentioned languages because in Salesforce SOQL is integrated with the Salesforce database.
When to Use SOQL
Simply, when you want to retrieve data from the Salesforce database we can use SOQL. That is when your Apex code has a requirement to get data from Salesforce for any reason like when modifying data, to know information about data or anything.
Significance of SOQL
SOQL is very important in the following ways
- It is used in writing triggers and apex classes to retrieve data and use it.
- No connecting to the database is required to fetch the data, you can directly query the data.
- SOQL is fully integrated with Salesforce to fetch the data seamlessly from the database.
- It is very easy to learn the language and complex operations can be done easily.
SOQL SELECT Syntax
SELECT and FROM are the basic keywords used in every SOQL queries. Basically, the SELECT keyword is used to select the fields we require to fetch and FROM keyword is used to define the object where these fields to be fetched from.
Hence, the syntax looks like,
SELECT Fields FROM Object
A basic example of SOQL query which fetches all the names and emails of all the contacts in salesforce object
SELECT Name, Email FROM Contact
Here, “Name” and “Email” are the fields that come after the SELECT keyword are the fields to be fetched and “Contact” is the object which comes after FROM keyword where these fields are to be fetched from.