Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

By Smriti Sharan

Interview Questions on
SOQL in
Salesforce
What is SOQL

SOQL Stands for Salesforce Object Query Language

SOQL can be considered as SQL for Salesforce

Use SOQL to query data in your org using SELECT

Statement
SOQL Query Structure
Build Queries out of Object
File ->Open->Objects ->Choose the Object -> Select the field ->Query
Build Queries out of Object
Parent to Child Query

Get name of accounts and related contacts

Note: For custom relationships you use the API name of the
relationship field, but with __r rather than __c.
Child to Parent Query
Use Dot Notation when looking for parent object record and querying
on child object.
What is 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.
What is dynamic SOQL?
Dynamic SOQL can be invoked by Database.query(query_string);
where query_string is the query generated at runtime. In operation
and processing, it works the same as Static SOQLs.

Example :

List<Contact> conList = Database.query(‘SELECT Id, Name FROM contact WHERE


firstname= \’sfdcamplified\’ ‘);
What is disadvantage of Dynamic SOQL?
One DISADVANTAGE with DYNAMIC SOQL is it causes SOQL
injection in where condition which fetching on the basis of some
text. To avoid which we need to use String.escapeSingleQuotes.
There is no possibility of these in Static SOQL.
How to use Datetime in Dynamic SOQL Query in Salesforce
Explain Group By
Explain Having
What is FOR UPDATE clause in soql?

For Update clause will lock the records from getting updated from
other transactions untill the current transaction is completed.
What is LIKE clause in soql?

A. like clause is used to compare the string values or used to search for
the string value in the given fields
‘%’ – any no of characters
‘_’ – one character
Syntax to fetch the records from recycle bin using soql?
SELECT Id, isDeleted FROM <Oblectname> WHERE isDeleted = true

All ROWS – This will only return the deleted rows.

SELECT Id, isDeleted FROM <Oblectname> WHERE isArchived =

true All ROWS – This will only return the archived rows.
How many records can be fetched using SOQL?
We can retrieve up to 50000 records from SOQL in a single

transaction.

If we want to Fetch more than 50000 records by SOQL, You should

look at using Batch Apex to accomplish your goals.


If you enjoyed the
learning, subscribe to
sfdcamplified

You might also like