Activity › Forums › Salesforce® Discussions › What Are The Types of SOQL Statements in Salesforce?
Tagged: Database.com, DML Operation, Dynamic SOQL, Salesforce Classes, Salesforce sObject, Salesforce Triggers, SOQL Statement, Static SOQL
-
What Are The Types of SOQL Statements in Salesforce?
Posted by Prachi on September 28, 2018 at 9:43 AMWhat Are The Types of SOQL Statements in SalesForce? Explain with Example
Parul replied 7 years, 7 months ago 3 Members · 3 Replies -
3 Replies
-
Hello,
Salesforce Object Query Language is used to query that records from the database.com based on the requirement.
There are 2 types of SOQL Statements.Static SOQL
Dynamic SOQL1.Static SOQL: The oStatic SOQL Statement is written in [] (Array Brackets)
This statements are similar to IINQ(Ion Integrated Query)
Example: String search for =’Jones’;
Contact[] contacts=[select testfield__c, FirstName, LastName from Contact Where Last Name=:search for];2. Dynamic SOQL:
It is used to refer to the creation of a SOQL string at run time with Apex code.
Dynamic SOQL enables you to create more flexible application.
To create Dynamic SOQL query at run time use Database.Query() method, in one of the following ways.
Return a single sObjects when the query returns a single record.
sObjects s = Database. Query(String_limit_l);
Return a list of sObjects when the query returns more than a single record.
Examples:
Eg1:
String myTestString = ‘TestName’;
List List= Database.Query(SELECT Id FROM MyCustomObject__c WHERE Name = :myTestString);
Eg2:
String resolviedfield L = myvariable.field__c;
List L = Database.Query(‘SELECT Id FROM myCustomObject__c WHERE field__c = ‘+resolvedfield_L); - [adinserter block='9']
-
SOQL statements evaluate to a list of sObjects, a single sObject, or an Integer for count method queries.
For example, you could retrieve a list of accounts that are named Acme:
<span> </span>List<Account<span class=”operator”>></span> aa <span class=”operator”>=</span> [select id, name from account where name <span class=”operator”>=</span> <span class=”string”>’Acme'</span>];
SOQL(Salesforce Object Query Language)
1)Using SOQL we can Search only on one object at a time.
2)We can query on all fields of any datatype
3)We can use SOQL in Triggers and classes.
4)We can perform DML operation on query results.SOSL(Salesforce object Search Language)
1)Using SOSL we can search on many objects at a time.
2)We can query only on fields whose data type is text,phone and Email.
3)We can use in calsses but not in Triggers.
4)We cannot perform DML operation on search result.There are 2 types of SOQL Statements.
Static SOQL:
Static SOQL means you are using some SOQL with any user input or hard code values like below query view source
List<Account> lstAccount = [select id,name form account where name =’Amit’];
Dynamic SOQL:Dynamic SOQL refers to the creation of a SOQL string at runtime 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 query looks like this…
List<sObject> L = Database.query(string); -
There are 2 types of SOQL Statements.
Static SOQL:
Static SOQL means you are using some SOQL with any user input or hard code values like below query view source
List<Account> lstAccount = [select id,name form account where name =’Amit’];Dynamic SOQL:
Dynamic SOQL refers to the creation of a SOQL string at runtime 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 query looks like this…
List<sObject> L = Database.query(string);Thanks
Log In to reply.