SOQL Practice

You might also like

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

SOQL Practice

Write a soql to fetch all the account records in the accending order of account
name
select name,Industry from Account order By Name ASC

Write a soql to fetch all the account records in the decending order of industry
select name,Industry from Account order by Name, Industry DESC

Write the soql to fetch last 10 opportunity records based on createddate


select name,stagename from Opportunity order by CreatedDate DESC LIMIT 10

Write a soql to fetch last 10 opportunities based on closeDate


select name,stagename from Opportuntiy order By CloseDate DESC LIMIT 10

Write a soql to fetch all the records including records which are in recyle bin
from Accoutn sobject
select id,name,Industry from Account ALL ROWS

Write soql query to fetch all the account records whose industry is Banking or
enery or Education.
select name,Industry,Phone from Account where Industry
In('Banking','Energy','Education')

Write a soql query to fetch all the Contact records whose lastname ends with s
select lastname,firstname,phone from Contact where Lastname LIKE '%s'

Write soql to fetch all the opportunity records which are going to closed in next
15 days
select id,name,amount from Opportunity where closeDate=NEXT_N_DAYS:15

LAST WEEK above (closed date) LAST_WEEK

Account and Cases are connected by Lookup


select name,Industry,(select origin,status from cases) from Account

-- filter above with accounts having cases


select id,Name,(Select origin,Status from cases) from Account where Id in (select
Accountid from case)

Account and Opportunity are connected by Lookup


select name,Industry,(select name,amount from Opportunities) from Account

SUB QUERIES

Get all accounts which do not have case


select id from Account where Id not in (select Accountid from case)

Get all accounts with case


elect id from Account where Id in (select Accountid from case)

You might also like