SOQL Basics for Salesforce Admins

Ditch Reports and VLOOKUPs Forever

If you have spent any amount of time in the Salesforce ecosystem as an admin, you know this exact routine:

SurveyVista: Effortless Data Collection to Action

A stakeholder asks for a dataset. You build a custom report type, drag and drop fields, apply filters, and hit Export. Then, because Salesforce reports cannot easily pull data across non-related branches or cross-reference two unconnected objects, you open Excel or Google Sheets. You waste 30 minutes writing nested VLOOKUP or XLOOKUP functions, cleaning up blank rows, and dealing with #N/A errors.

What if you could bypass the Report Builder, skip Excel entirely, and extract precise, relational datasets straight from Salesforce in seconds?

Meet SOQL: The Admin Query Tool Hiding in Plain Sight

SOQL stands for Salesforce Object Query Language. It is a lightweight, declarative query syntax used to read data stored in your Salesforce database. Think of it as asking Salesforce a direct question: “Give me these specific fields, from this object, where these conditions are met.”

While SOQL is often labeled as a “developer tool,” it is actually one of the most powerful super-skills a Salesforce Administrator can learn. In this guide, we will cover the basics of SOQL, demonstrate how to construct powerful queries with sorting and grouping, and show you how to leverage Salesforce Inspector to execute queries faster than you ever thought possible.

Why SOQL Beats Standard Reports and Excel

  • No Report Limits: Standard Salesforce reports cap you at 2,000 rows in the UI, and multi-block joined reports can be clunky. SOQL lets you quickly inspect thousands of records at once.
  • Access “Hidden” Objects: Certain system objects, such as FieldPermissions, UserRecordAccess, ApexClass, or GroupMember, are impossible or difficult to query via standard report types. SOQL gives you direct visibility into almost every object in your org.
  • Say Goodbye to VLOOKUPs: Instead of exporting Contacts to Sheet A and Accounts to Sheet B to run a VLOOKUP, SOQL allows you to reach across relationships directly in a single line of query text.
  • Data Operations Ready: When you pull data via SOQL, you get precise 18-character Record IDs, making the export immediately formatted and ready for Data Loader or inline updates.

Understanding SOQL Query Structure

Every basic SOQL query relies on three core clauses: SELECT, FROM, and WHERE.

Free Mentorship With Talent Stacker
SELECT Id, Name, StageName, Amount 
FROM Opportunity 
WHERE IsClosed = False

Let’s break this down:

  • SELECT: The specific Field API Names you want to retrieve. (Tip: Always use API names, such as Custom_Field__c, not field labels).
  • FROM: The API Name of the Salesforce object you are querying (e.g., Account, Contact, Custom_Object__c).
  • WHERE: The filtering conditions. Only records meeting these criteria will be returned.

Essential SOQL Clauses and Operators

To make your queries more precise, you can append additional clauses:

  • ORDER BY: Sorts your records in ascending (ASC) or descending (DESC) order.
  • LIMIT: Restricts the maximum number of records returned (e.g., LIMIT 100).
  • IN: Filters against a list of values (e.g., WHERE StageName IN (‘Closed Won’, ‘Closed Lost’)).
  • LIKE: Performs wild-card searches using % (e.g., WHERE Email LIKE ‘%@gmail.com’).

Master Sorting with ORDER BY (Ascending vs. Descending)

When querying individual records, use ORDER BY with ASC (smallest to largest / A to Z) or DESC (largest to smallest / Z to A). If unspecified, SOQL defaults to ASC.

When you add multiple fields separated by a comma after ORDER BY, it creates a primary sort and a secondary sort (tie-breaker).

Example: Primary & Secondary Sorting (DESC / DESC)

Goal: Pull open Opportunities, sorted so the highest-value deals appear at the top (DESC), followed by the most recently created deals (DESC).

SELECT Id, Name, Amount, StageName, CloseDate 
FROM Opportunity 
WHERE IsClosed = False 
ORDER BY Amount DESC, CloseDate DESC 
LIMIT 50

How Salesforce Evaluates Multi-Field Sorting Step-by-Step

  1. Primary Sort (Amount DESC): Salesforce first sorts all records by Amount from highest to lowest.
  2. Secondary Sort (CloseDate DESC): If two or more opportunities have the exact same Amount, Salesforce uses CloseDate to break the tie, placing the one with the most recent CloseDate higher up.

Replacing VLOOKUPs with Relationship Queries

The real magic of SOQL lies in traversing relationships. In Excel, you use VLOOKUP to match an Account ID on a Contact sheet to fetch the Account Owner’s email. In SOQL, you traverse the relationship directly using dot notation (Parent Queries) or subqueries (Child Queries).

Parent Relationship Queries (Child-to-Parent)

When querying a child object (like Contact), you can traverse “up” to the parent object (Account) using dot notation.

Excel approach: Export Contacts, Export Accounts, run =VLOOKUP(C2, Accounts!A:D, 4, FALSE).

SOQL approach:

SELECT Id, FirstName, LastName, Account.Name, Account.Owner.Email, Account.Industry 
FROM Contact 
WHERE Account.Rating = 'Hot'

Notice how Account.Owner.Email reaches up three levels (Contact > Account > Owner) in a single query. No spreadsheets required.

Rule of Thumb for Custom Objects: For custom lookup fields, change the __c to an __r. For example, if you have a custom lookup Building__c on Contact, query it as Building__r.Name.

Child Relationship Queries (Parent-to-Child)

What if you want to pull a list of Accounts alongside all of their related Opportunities?

SOQL approach (Subquery):

SELECT Id, Name, AnnualRevenue, 
       (SELECT Id, Name, Amount, StageName FROM Opportunities) 
FROM Account 
WHERE Type = 'Customer - Direct'

This returns every Direct Customer Account and embeds an array of its related Opportunities right inside the record row.

Enter Salesforce Inspector: The Admin’s Best Friend

While you can run SOQL inside the native Salesforce Developer Console, Web Console or VS Code, the absolute best tool for admins is Salesforce Inspector (or its popular community extension, Salesforce Inspector Reloaded).

VS Code Web Console showing a SOQL aggregate query and its output panel with results grouped by LeadSource
Salesforce Web Console

Salesforce Inspector is a browser extension (available for Chrome, Firefox, and Edge) that adds a subtle overlay tab to your browser when logged into Salesforce.

Why Use Salesforce Inspector for SOQL?

  1. Instant Access: You don’t need to open Setup or launch a heavy development environment. Just click the overlay, select Data Export, and start typing.
  2. Auto-Completion: As you type your SOQL query, Salesforce Inspector auto-completes object and field API names in real time, saving you from constantly checking the Object Manager.
  3. One-Click Export Options: Once your query executes, you can instantly copy the results as CSV, Excel, or JSON.
  4. Direct Record Navigation: Record IDs in the Inspector results grid are clickable links. Want to inspect a returned Account? Just click its ID to open the record directly in Salesforce.
  5. Inline Data Cleanup: If you find bad data in your query results, Salesforce Inspector allows you to update or delete those records right from the tool interface.
Salesforce Inspector Data Export tool showing the SOQL query editor, field suggestions, and results table
Salesforce Inspector Reloaded

Practical SOQL Recipes for Admins

To help you get started, here are three real-world administrative tasks solved with a simple SOQL query instead of complex reports or spreadsheets:

Recipe 1: Find Active Users with No Assigned Permission Sets

Find out which active users are missing a key organizational permission set.

SELECT Id, Name, Email, Profile.Name 
FROM User 
WHERE IsActive = True 
  AND Id NOT IN (
      SELECT AssigneeId 
      FROM PermissionSetAssignment 
      WHERE PermissionSet.Name = 'Sales_Operations_Admin'
  )

Recipe 2: Audit Contacts with Inconsistent Address Data

Locate contacts where the mailing country is missing, but the parent Account has a billing country populated.

SELECT Id, FirstName, LastName, MailingCountry, Account.Id, Account.Name, Account.BillingCountry 
FROM Contact 
WHERE MailingCountry = NULL 
  AND Account.BillingCountry != NULL

Recipe 3: Aggregate Pipeline Metrics with GROUP BY and ORDER BY

Want a quick summary of your pipeline grouped by lead source without building a summary report? Combine aggregate functions like SUM() and COUNT() with GROUP BY and ORDER BY.

The GROUP BY clause works like a Pivot Table in Excel. It collapses individual records into summary rows based on shared values in a specific field. When you group by LeadSource, Salesforce automatically organizes all open opportunities into distinct buckets (like “Partner Referral” or “Web”) and calculates aggregate metrics such as COUNT(Id) for total deal volume and SUM(Amount) for total pipeline value for each bucket in a single clean table.

SELECT LeadSource, COUNT(Id) TotalDeals, SUM(Amount) TotalPipeline 
FROM Opportunity 
WHERE IsClosed = False 
GROUP BY LeadSource 
ORDER BY SUM(Amount) DESC
Salesforce Inspector Export Result grid showing aggregated SOQL results by LeadSource with Copy Excel, CSV, and JSON export options
Salesforce Inspector Reloaded SOQL Query Results

Become a More Efficient Salesforce Admin with SOQL

Learning SOQL is about becoming a dramatically more efficient Administrator. Once you get comfortable writing basic SELECT … FROM … WHERE queries in Salesforce Inspector, you will find yourself relying less on complex Excel formulas and spending far less time building disposable one-off reports.

Install Salesforce Inspector or spin up the Web Console initially in a sandbox org, and run your first query today. Your future self (and your spreadsheets) will thank you.

Explore related content:

Can You Use DML or SOQL Inside the Loop?

Slack Code: AI Coding Agents Have Entered the Team Chat

Setup with Agentforce: What Admins Can Actually Do Right Now

Andy Engin Utkan

Andy Engin Utkan is a Salesforce MVP with 24 certifications. He is the founder of Salesforce Consulting Partner BRDPro Consulting. Utkan is a consultant, trainer, and content creator, focusing on automating business processes using Salesforce flow. He is recognized for his expertise in Salesforce flow, providing guidance through various courses and contributing actively to the Salesforce community.

Leave a Reply

Back to top button

Discover more from Salesforce Break

Subscribe now to keep reading and get access to the full archive.

Continue reading