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 start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

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