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?

  1. SOQL queries is used to retrieve data from single object or from multiple objects.
  2. SOQL is used to count the number of records that meets the evaluation criteria.
  3. It is used to sort results.
  4. It is used to retrieve data from number, data and checkbox fields.
  5. Salesforce Object query language (SOQL) is used in the queryString parameter in the query ( ) call.
  6. In Apex statement.
  7. In visualforce controllers and getter methods.
  8. 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.

SOQL Statement

Select PHONE, Name From ACCOUNT
How to write first SOQL Query

As shown above, Phone number and name for standard field of the Account object are extracted.

Select Name, Phone, AnnualRevenue, CustomerPriority__c FROM ACCOUNT
How to write first SOQL Query

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
First soql statement using force.com explorer

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.

Conclusion

In this Salesforce Developer Tutorial, we learned how to write our first SOQL Query.