Hi Guys!!
I came up with today's topic.
Comparison Operators in SOQL:
I came up with today's topic.
Comparison Operators in SOQL:
Using of
this comparison operator we will compare the values in where Condition.
Operator
|
Description
|
=
|
Equals (Using of the Equals We will
compare two different values)
Return true if both values compare.
|
!=
|
Not Equals (Using of the Not Equals We
will compare two Different values)
Return true if both values not
compare.
|
<
|
Less than
|
<=
|
Less than or equal
|
>
|
Greater than
|
>=
|
Less than or equal
|
>
|
Greater than
|
>=
|
Greater than or equal
|
IN
|
In
|
NOT IN
|
Not in (WHERE clause)
|
INCLUDES
EXCLUDES
|
Applies to multi-select picklists
|
Some Examples on SOQL:
I want display all the accounts in a
Table ? What we need to do?
Page:
<apex:page controller="SOQLDemo" sidebar="false">
<apex:form >
<apex:pageBlock title="SOQL
Demo">
<apex:pageBlockSection
title="SOQL Demo" columns="1">
<apex:pageBlockTable
value="{!Accountdata}" var="s">
<apex:column
value="{!s.Name}"/>
<apex:column
value="{!s.ID}"/>
<apex:column
value="{!s.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
public class
SOQLDemo
{
public
list<Account> Accounts{get;set;}
Public list<Account> getAccountdata()
{
Accounts = [select id,Name,phone from
Account];
return Accounts ; } }
SOQL Joins & Soql Locking
statements:
Using of the SOQL Joins we will retrieve the data from their
related object.
Example:
Q1. I want to write a
query on Child object and we need to retrieve their related Parent records?
Select id,Name,Phone,Email,Account.Name
from contact
We are writing query on Parent object and we are retrieving
the records from their related Parent.
Q2. I want to write a
query on Parent object and we need to retrieve their related child records?
Select id,Name,(select id,Name
from contact) from Account
Here we are retrieving the Account
their related contacts.
SOQL Locking Statement:
Using of the SOQL Update statement we will lock the SObject
records in Salesforce. While a sObject record is locked, no other client or
user is allowed to make updates either through code or the Salesforce user
interface. The lock gets released when the transaction completes.
Syntax: Select
id,Name,Phone from Account where Name=’IBM’ For Update;
During this transaction we cannot edit these IBM records
using Data management Tools are UI.
Important Points
on SOQL Update:
- While the records are locked by a client, the locking client can modify their field values in the database in the same transaction.
- Other clients have to wait until the transaction completes and the records are no longer locked before being able to update the same records. Other clients can still query the same records while they’re locked
- We cannot specify the Order by if you are using SOQL update statement.
- The Apex runtime engine locks not only the parent sObject record but all child records as well. So if you lock the parent object records all the associate child records also got locked. Syntax:
Select
Field1, Field 2, Field 3 --- from Object FOR Update
Example Code:
Public class SOQLlocking
{
Public
list<Account> getAccountRecords()
{
list<Account> AccountRecords
= [select id,Name,Phone from Account where Name Like ‘%Karthik Training%’ FOR Update];
return AccountRecords;
}
}
In the above Code I lock all the Karthik Training records, while this transaction any user try to change the record user will
notify with the error.
Once the transaction completed then we will update this
records also.
SOQL Interview questions:
1. What is SOQL?
SOQL stands for Salesforce object query
language, using of the SOQL we will retrieve the data from single object and
related object.
Ex: if we want to retrieve the data from
Account object,
Select id,Name,Phone from Account
2. What are the Governor limits of SOQL?
We will write maximum of 100 SOQL,
using of one SOQl we will retrieve 50000 records.
Total number of SOQL queries issued for Batch Apex and future
methods is 200
3 3. What is the return type for SOQL queries?
Soql will return Integer datatype,
List of Sobject and Single subject.
No comments:
Post a Comment