SOQL Statements and Salesforce Object Search language (SOSL) statements can be evaluated by surrounding the statement with square brackets [ ]. Salesforce Apex code contains many programming elements like Variable declaration, SOQL Query, Control Structure, Array (list), Data (DML) operation.
SOQL and SOSL queries are case-insensitive like Salesforce Apex. A SOQL query is the equivalent of a SELECT SQL statement and searches the organisation database. We suggest salesforce user to use Salesforce keywords in uppercase and fields in Lowercase.
When is SOQL Query used?
- SOQL queries is used to retrieve data from single object or from multiple objects.
- SOQL is used to count the number of records that meets the evaluation criteria.
- It is used to sort results.
- It is used to retrieve data from number, data and checkbox fields.
- Salesforce Object query language (SOQL) is used in the queryString parameter in the query ( ) call.
- In Apex statement.
- In visualforce controllers and getter methods.
- In the schema explorer of the force.com IDE.
How to Write first SOQL Query in Force.com Explorer?
In Salesforce Apex coding, the API names of the object are required in SOQL. SOQL statements evaluates to a list of sObjects, a single sObject, or an Integer for count method queries. Before getting started with writing our first SOQL statements we need to install Force.com Explorer. We can also use third party tools to write and execute queries in Salesforce.com.
Select PHONE, Name From ACCOUNT
As shown above, Phone number and name for standard field of the Account object are extracted.
Select Name, Phone, AnnualRevenue, CustomerPriority__c FROM ACCOUNT
As shown in above example, we fetching custom fields in the Standard Object. Here Name and Phone are Standard fields where CustomePriority__c is the custom field.
SELECT name,State__c, College__C FROM Student__c
As shown in above SOQL statement,Student__c is a custom object where State__c and College__c are custom fields. Student name , state and college details are retrieved from the custom objectStudent__c.
In this Salesforce Developer Tutorial, we learned how to write our first SOQL Query.