SOQL Query Library for Salesforce Admins
Every page here is one job an admin actually has: count the records before a mass update, find the blanks, catch the duplicates, see what changed today. The query is at the top, the explanation is underneath, and the pitfalls are the ones that cost real time.
Queries use standard fields only, so they run as-is in any org. Swap the object's API name to adapt one to a custom object.
70 pages
Counting and aggregates
- SOQL Query to Count Accounts in SalesforceCopy-paste SOQL to count accounts in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Accounts by IndustryAggregate SOQL that breaks accounts down by Industry, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Contacts in SalesforceCopy-paste SOQL to count contacts in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Contacts by LeadSourceAggregate SOQL that breaks contacts down by LeadSource, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Leads in SalesforceCopy-paste SOQL to count leads in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Leads by LeadSourceAggregate SOQL that breaks leads down by LeadSource, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Opportunities in SalesforceCopy-paste SOQL to count opportunities in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Opportunities by StageNameAggregate SOQL that breaks opportunities down by StageName, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Cases in SalesforceCopy-paste SOQL to count cases in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Cases by StatusAggregate SOQL that breaks cases down by Status, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Users in SalesforceCopy-paste SOQL to count users in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Users by ProfileIdAggregate SOQL that breaks users down by ProfileId, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Tasks in SalesforceCopy-paste SOQL to count tasks in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Tasks by StatusAggregate SOQL that breaks tasks down by Status, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Campaigns in SalesforceCopy-paste SOQL to count campaigns in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Campaigns by TypeAggregate SOQL that breaks campaigns down by Type, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Products in SalesforceCopy-paste SOQL to count products in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Products by FamilyAggregate SOQL that breaks products down by Family, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query to Count Orders in SalesforceCopy-paste SOQL to count orders in Salesforce, with variants for filtered counts, COUNT(Id) vs COUNT(), and grouped totals.
- SOQL GROUP BY: Orders by StatusAggregate SOQL that breaks orders down by Status, with COUNT, SUM, and the AggregateResult alias rules.
Date and time filters
- SOQL Query for Accounts Created in the Last 30 DaysSOQL for accounts created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Accounts Modified TodaySOQL for accounts changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Contacts Created in the Last 30 DaysSOQL for contacts created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Contacts Modified TodaySOQL for contacts changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Leads Created in the Last 30 DaysSOQL for leads created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Leads Modified TodaySOQL for leads changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Opportunities Created in the Last 30 DaysSOQL for opportunities created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Opportunities Modified TodaySOQL for opportunities changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Cases Created in the Last 30 DaysSOQL for cases created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Cases Modified TodaySOQL for cases changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Users Created in the Last 30 DaysSOQL for users created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Users Modified TodaySOQL for users changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Tasks Created in the Last 30 DaysSOQL for tasks created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Tasks Modified TodaySOQL for tasks changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Campaigns Created in the Last 30 DaysSOQL for campaigns created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Campaigns Modified TodaySOQL for campaigns changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Products Created in the Last 30 DaysSOQL for products created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Products Modified TodaySOQL for products changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Orders Created in the Last 30 DaysSOQL for orders created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Orders Modified TodaySOQL for orders changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
Data quality
- SOQL Query to Find Accounts With a Blank IndustryFind accounts with an empty Industry using SOQL, including the NULL syntax, blank-string gotcha, and a count-first workflow.
- SOQL Query to Find Duplicate Accounts by NameFind duplicate accounts in Salesforce with a GROUP BY / HAVING SOQL query on Name, then pull the underlying record IDs.
- SOQL Query to Find Contacts With a Blank EmailFind contacts with an empty Email using SOQL, including the NULL syntax, blank-string gotcha, and a count-first workflow.
- SOQL Query to Find Duplicate Contacts by EmailFind duplicate contacts in Salesforce with a GROUP BY / HAVING SOQL query on Email, then pull the underlying record IDs.
- SOQL Query to Find Leads With a Blank EmailFind leads with an empty Email using SOQL, including the NULL syntax, blank-string gotcha, and a count-first workflow.
- SOQL Query to Find Duplicate Leads by EmailFind duplicate leads in Salesforce with a GROUP BY / HAVING SOQL query on Email, then pull the underlying record IDs.
- SOQL Query to Find Opportunities With a Blank AmountFind opportunities with an empty Amount using SOQL, including the NULL syntax, blank-string gotcha, and a count-first workflow.
- SOQL Query to Find Cases With a Blank ContactIdFind cases with an empty ContactId using SOQL, including the NULL syntax, blank-string gotcha, and a count-first workflow.
- SOQL Query to Find Products With a Blank ProductCodeFind products with an empty ProductCode using SOQL, including the NULL syntax, blank-string gotcha, and a count-first workflow.
- SOQL Query to Find Duplicate Products by ProductCodeFind duplicate products in Salesforce with a GROUP BY / HAVING SOQL query on ProductCode, then pull the underlying record IDs.
Reporting
- SOQL Query for the Latest Accounts (ORDER BY and LIMIT)Return the most recent accounts with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Contacts (ORDER BY and LIMIT)Return the most recent contacts with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Leads (ORDER BY and LIMIT)Return the most recent leads with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Opportunities (ORDER BY and LIMIT)Return the most recent opportunities with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Cases (ORDER BY and LIMIT)Return the most recent cases with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Users (ORDER BY and LIMIT)Return the most recent users with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Tasks (ORDER BY and LIMIT)Return the most recent tasks with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Campaigns (ORDER BY and LIMIT)Return the most recent campaigns with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Products (ORDER BY and LIMIT)Return the most recent products with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Orders (ORDER BY and LIMIT)Return the most recent orders with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
Ownership and assignment
- SOQL Query: Accounts by Owner in SalesforceQuery accounts by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Contacts by Owner in SalesforceQuery contacts by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Leads by Owner in SalesforceQuery leads by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Opportunities by Owner in SalesforceQuery opportunities by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Cases by Owner in SalesforceQuery cases by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Tasks by Owner in SalesforceQuery tasks by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Campaigns by Owner in SalesforceQuery campaigns by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
- SOQL Query: Orders by Owner in SalesforceQuery orders by owner in SOQL - filter on OwnerId, dot-walk to Owner.Name, and count records per owner before a reassignment.
Relationship queries
- SOQL Query: Accounts With Their ContactsParent-to-child SOQL that returns accounts together with their contacts, plus the relationship-name rules for custom objects.
- SOQL Query: Campaigns With Their Campaign membersParent-to-child SOQL that returns campaigns together with their campaign members, plus the relationship-name rules for custom objects.
Other resources
- Salesforce Admin How-To GuidesStep-by-step guides for the Salesforce admin tasks that come back every week: profile comparison, data export, permissions, org limits, metadata, and safe mass updates.
- Salesforce Admin Tool ComparisonsHonest comparisons of the tools Salesforce admins use every day - Salesforce Inspector, Workbench, Data Loader, and the CLI - and where each one fits.
- Salesforce Admin GlossaryPlain-English definitions of the Salesforce terms admins run into daily - SOQL, governor limits, permission sets, field-level security, record types, and more.