+1 vote
in Salesforce by
What Are The Types of SOQL Statements in SalesForce?

1 Answer

0 votes
by
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 SOQL

Static SOQL:

The Static SOQL Statement is written in []  (Array Brackets)

These statements are similar to IINQ (Ion Integrated Query)

Example:

1

2

String search for =’Jones’;

Contact[] contacts=[select testfield__c, FirstName, LastName from Contact Where Last Name=:search for];

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 a 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.

Example 1:- Queries

1

2

String myTestString = ‘TestName’;

List List= Database.Query(SELECT Id FROM MyCustomObject__c WHERE Name = :myTestString);

Example 2:- Queries

1

2

String resolvedfield L = myvariable.field__c;

List L = Database.Query(‘SELECT Id FROM myCustomObject__c WHERE field__c = ‘+resolvedfield_L);

Related questions

0 votes
asked Sep 24, 2019 in Salesforce by Robin
0 votes
asked Feb 3, 2020 in Salesforce by SakshiSharma
0 votes
asked Sep 23, 2019 in Salesforce by john ganales
...