SOQL in Salesforce

Learn All About SOQL in Salesforce


SOQL is a language that extracts data from the Salesforce database. In Object-Oriented Programming for Admins you found that you can use Data Manipulation Language (DML) statements to insert, update, and erase records. In any case, imagine a scenario in which you need to get information that as of now exists in the database. SOQL simplifies it to recover information. 

Making SOQL inquiries is like making a report. At the point when you make a report, you answer questions, for example, 

  • What fields would I like to show? 
  • Where data is located?

Required SOQL Clauses:


Every SOQL query is formed with two clauses initially i.e. SELECT clause and FROM clause. Consider a clause a piece of a riddle. It's one piece of a total query. 

Each SOQL query starts with the keyword SELECT. The SELECT clause indicates one or more than one field (isolated by commas) in a Salesforce record

Note: when an admin converse with another admin, they doubtlessly allude to the field by its field label. In any case, in code, developers use API names for all things considered. So in your SOQL questions, consistently use field API names, not field labels.

dont miss out iconDon't forget to check out: Batch Apex in Salesforce (Basics, Governor Limits, Custom Iterable of Batch)


The resulting clause that is expected to make a SOQL query is the FROM clause. 

Starting with the FROM keyword, the FROM clause decides an object in your Salesforce database.

Optional SOQL Clause:

The SELECT clause and the FROM clause is required, yet SOQL furthermore has discretionary clauses to refine your query. 


The WHERE clause sets the conditions that a record should match to be picked and returned. Use the WHERE clause the same way you use filters to restrict the data shown in a rundown view or report. For instance, in case we're searching for a contact whose first name is Steven, we can add WHERE FirstName = 'Steven' to the furthest limit of our query.

You can in like manner describe the WHERE clause to filter using more than one condition. There are various approaches to do this utilizing three operators: AND, OR, and IN.


With the assistance of the LIMIT keyword, we can characterize the greatest number of records to return. LIMIT is important when you're endeavouring and don't have any desire to trust that a query will manage a huge amount of information. 

dont miss out iconCheck out another amazing blog by Shweta Choudhary here: All About Apex Testing in Salesforce


Since you have an idea in regards to the proportion of results, how might you coordinate those results? ORDER BY clause is utilized to sort results get by the query as indicated by the worth of a particular field Optionally, utilize a qualifier in an ORDER BY clause to choose ascending order (default) or descending order. 


Like Operators in SOQL go presumably as a Comparison administrator for String Field Expression. Expression is considerable if the worth in the predefined fieldName matches the characters of the text string in the destined worth. The LIKE administrator in SOQL and SOSL takes after the LIKE administrator in SQL; it gives a system to arrange with halfway text strings and joins support for uncommon characters.


Popular Salesforce Blogs