Introduction to SOQL in Salesforce?

on

|

views

and

comments

Table of Contents

Introduction to SOQL

SOQL (Salesforce Object Query Language) is a query language that searches for and retrieves data from Salesforce objects. SOQL is similar to SQL, but it is specifically designed for the Salesforce platform and supports features such as relationship queries and custom object searches.

Let’s take an example here, suppose you want to get the below information about a person 

  1. Name
  2. Age
  3. Relationship

If you have a table where the information is stored. You make a query to get the details

Syntax of SOQL

SELECT FieldAPIName1, FieldAPIName2 FROM Object_ApiName__c(Account/Contact/Payment__c)

SELECT one or more fields

FROM an object
WHERE filter statements
results are ordered (optional)

Here are some key concepts and examples of SOQL in Salesforce:

  • WHERE
    • Single Filter – ( Name = ‘United Oil’)
    • Multiple Values Filter – Name IN (‘United Oil’, ‘Acme’)
    • Like Filter – Name Like ‘%United Oil’
      • %abc% – Keyword is found anywhere in the name
      • %abc – The starting char could be anything but the ending will always be abc
      • abc% – Starting will always be ABC and the ending will be anything
    • Not Like Filter
      • Not Name Like ‘TEST%’
    • CreatedDate > 2021-09-12T22:16:30.000Z
  • ORDER BY
    • ORDER BY Name DESC
    • ORDER BY Name ASC
  • LIMIT
    • LIMIT 200
  • COUNT()
    • COUNT()
    • COUNT(ID)
    • COUNT(AnnualRevenue)
  • GROUP BY – Aggregate Query
    • Aggregate Methods
      • count
      • sum
        • Integer
        • Number
        • Currency
      • min
        • Integer
        • Number
        • Currency
        • Date
        • DateTime
      • max
        • Integer
        • Number
        • Currency
        • Date
        • DateTime
    • GROUP BY Name
    • GROUP BY ROLLUP(LeadSource)
    • GROUP BY ROLLUP(Status, LeadSource)
    • GROUP BY CUBE(Type, BillingCountry)

How the Query should be formed

The Key Element or the Keywords that we have just talked about should be placed in the right place otherwise the SOQL will not work.

Below image shows at which place we need to which keyword

Watch Complete Video Here

Assignment

  • List All the Contact Records
  • List All the Contact Records where the Email is not blank
  • List All the Contact Records Where the Email is Blank
  • List All the Contact Records Where the Title contains the developer
  • List All the Contact Records Where the Title Starts with the Manager
  • List All the opportunities where the Amount is more than 29000
  • List All the Opportunity count state-wise
  • List All the Opportunity Amount Stage Wise
  • List All the Open & Closed Opportunities

Resources

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential