Selesforce
SOQL Query
Cheat Sheet
Salesforce SOQL Query
1) Query on Account Object to get the ID, Name and DeveloperName.
SELECT Id, Name, DeveloperName FROM Account
2)Query on Profile Object to get the Profile Id and Name With Where
condition to check id contain the Id which we are passing into the profile
Id variable.
SELECT Id, Name From Profile WHERE Id =: ‘profileId’
3)Query to get the AssigneeId to which user we have assign the
Permissionset. In the where condition need to add the name of the
Permission set.
SELECT AssigneeId FROM PermissionSetAssignment WHERE
PermissionSet.Name =: ‘ add Permission set name’
4)Query to get all the Opportunity which contain the amount greater
than 10000
SELECT Id, Name, StageName, Amount FROM Opportunity WHERE
Amount > 10000
5)Query on Record Type to get the Record Type which contain the
developer name as Service
SELECT Id, Name ,SobjectType , DeveloperName FROM RecordType
WHERE DeveloperName = 'Service'
6) Query to get the Faderation Identifier from the User Object and in the
where condition we are passing the Id is equal to the reference of User Id
SELECT Id , FederatioIdentifier FROM User WHERE Id = ‘UserID’;
7)Query to get the Opportunity With Created Date is in the Decending
Order
SELECT Id, AccountId, RecordTypeId, IsPrivate, Name, Description,
StageName, Amount, Probability FROM Opportunity WHERE AccountId =:
'AccountIdreference' Order By CreatedDate DESC
8)Query to get the 5 Record of an Product2 Object to get only five record
we can use LIMIT
SELECT Id, Name, ProductCode, Description, CreatedDate, CreatedById,
LastModifiedDate, LastModifiedById, IsArchived FROM Product2 Limit 5
9)Query to get the Opportunity based on the Created Date in Assending
order
SELECT Id, AccountId, RecordTypeId, IsPrivate, Name, Description,
StageName, Amount, Probability FROM Opportunity WHERE AccountId =:
'AccountIdreference' Order By CreatedDate ASC
10)Query to get Child object Contact from the Parent Object Account
SELECT Name, Id, (SELECT Id, AccountId, LastName, FirstName, Salutation,
Name FROM Contacts) FROM Account
11)Query to get the the record of an Opportunity Object which is
Created This month
SELECT Id, Name, StageName, Amount FROM Opportunity WHERE
CreatedDate = THIS_MONTH
12)Query to get the the record of an Opportunity Object in Which the
StageName = ‘Closed Won’
SELECT Id, Name, StageName, Amount FROM Opportunity WHERE
StageName = 'Closed Won'
13) Query to get the Account record Shared User Data
SELECT Id, AccountId, UserOrGroupId, AccountAccessLevel,
OpportunityAccessLevel, CaseAccessLevel, ContactAccessLevel,
RowCause FROM AccountShare Limit 5
14) Query to get the First name , Last Name and Phone From the Lead In
Which the lead Id is in the LeadIDS reference List
Set<Id> leadldsList = New Set<Id>();
SELECT Id , FirstName,LastName Phone From Lead WHERE Id IN :
‘leadldsList’
15) Query to get the RecordType Id From RecordType IN which the
ObjectType is contact.
SELECT IdFROM RecordType WHERE SObjectType = ‘Contact’ AND Name
= ‘add name reference’
16) This query retrieves the ID, First Name, and Last Name of
Contacts with email addresses ending in '@example.com'
SELECT Id, FirstName, LastName FROM Contact WHERE Email LIKE
'%@example.com%
17) This query retrieves the ID, First Name, and Last Name of
Contacts associated with the Account named 'Acme Corporation'.
SELECT Id, FirstName, LastName FROM Contact WHERE
Account.Name = 'Acme Corporation'
18) This query retrieves the ID, Name, and Stage Name of
Opportunities with a Close Date within the next 30 days
SELECT Id, Name FROM Account WHERE LastActivityDate >
LAST_MONTH
19) This query retrieves the ID and Name of Accounts not
associated with the industry 'Finance'.
SELECT Id, Name FROM Account WHERE Industry != 'Finance'
20)This query retrieves the ID and Name of Accounts with Billing
City not containing the term 'York’
SELECT Id, Name FROM Account WHERE BillingCity NOT LIKE
'%York%'
21)This query retrieves the ID, Name, and Stage Name of
Opportunities not in the 'Prospecting' or 'Closed Lost' stages.
SELECT Id, Name, StageName FROM Opportunity WHERE
StageName NOT IN ('Prospecting', 'Closed Lost')
22)This query retrieves the ID, Name, and Close Date of
Opportunities with a Close Date within the current fiscal year.
SELECT Id, Name, CloseDate FROM Opportunity WHERE CloseDate
= THIS_FISCAL_YEAR
23) This query retrieves the ID, Name, and Close Date of
Opportunities with a Close Date within the current fiscal year
SELECT Id, Title, Body FROM Note WHERE ParentId IN (SELECT Id
FROM Opportunity WHERE CloseDate = THIS_FISCAL_YEAR)
Follow for more updates and insights