0% found this document useful (0 votes)
76 views9 pages

7 Ways To Use SOQL

Uploaded by

subakirudhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views9 pages

7 Ways To Use SOQL

Uploaded by

subakirudhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

7 Ways to Retrieve

Data Using SOQL


in Salesforce
Salesforce Apex Tutorial

Let's Connect and


Grow Together
@ soham-datta
The Simple Query:

List<Contact> lstContacts =
[SELECT Id, Name, Phone, BirthDate
FROM Contact]

@ soham-datta
Construct Map:

Map<Id, Account> mapAccounts =


new Map<Id, Account>
([SELECT Id, Name FROM Account])

@ soham-datta
Parent Child Relationship:

List<Account> lstAccounts =
[SELECT Id, Name,
(SELECT Name FROM Contacts)
FROM Account]

@ soham-datta
Child Parent Relationship:

List<Contact> lstContacts =
[SELECT Id, Name, Phone, Sex__c,
Account.Website, Account.Name
FROM Contact]

@ soham-datta
Aggregate Query:

List<AggregateResult> grpResults =
[SELECT Name, AVG(Amount)aver
FROM Opportunity
Group By Name
Having AVG(Amount) > 50000];

Object avgAmount =
grpResults[0].get('aver');

@ soham-datta
Dynamic Query:

String query = 'SELECT Id, Name,


Phone, BirthDate FROM Contact';

List<sObject> lstContacts =
Database.query(string);

@ soham-datta
Count Query:

Integer numOfAccRecords =
[ SELECT COUNT()
FROM Account
WHERE Name LIKE 'a%'];

@ soham-datta
Let's Connect
@ soham-datta

@ soham-datta

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy