Difference between Static SOQl and Dynamic
SOQl
Difference between Static SOQl and Dynamic SOQl
Salesforce Object Query Language (SOQL) is used to search records in your Salesforce organisation. SOQl
queries are two types they are Static SOQL and Dynamic SOQl.
Static SOQl statements.
Static SOQl query is written in [ ] (array brackets). It is good to use when you didn’t have any dynamic changes
in the soql query. when the fields names or where conditions is needed to be defined dynamically we didn’t use
static SOQL.
Contact[] contacts = [SELECT testfield__C, FirstName, LastName FROM Contact WHERE LastName =
Dynamic SOQL
Dynamic SOQL refers to the creation of a SOQl string at run time with Apex code. Dynamic SOQL enables you
to create more flexible applications. For example, you can create a search based on input from an end user, or
update records with varying field names. This is the major difference between soql and dynamic soql.
Dynamic SOQL enables to create more flexible applications.
To create Dynamic SOQL query at run time use Database.query(); method.
To create Dynamic SOQL query at run time, use the database query method as shown below.
List<sObject> sObject = Database.query(string);
Home
✦ What is SOQL?
✦ What is SOQL?
Learn Apex : Introduction to SOQL.
✦ Difference between SOQL and Dynamic SOQL
✦ How to Enable Developing Mode in Salesforce?
✦ How to use Salesforce developer Console.
✦ SOQL Syntax and Classes.
✦ How to write First SOQL Statement using Force.com Explorer?.
✦ How to know API name for objects and fields
➩ Difference between Static and Dynamic SOQL.
✦ Alias Notation.
✦ SOQL - IN Operator..
✦ Difference between SOQL and SOSL.
Learn Apex - SOSL