GlossaryTechnology

SOQL

Term 209 of 268 · Technology

In one sentence

SOQL (Salesforce Object Query Language) is Salesforce's query language for reading data from its objects. It looks like SQL but only queries records (it does not insert or delete) and respects the platform's data model and permissions.

Reviewed by Juan Manuel Garrido

Co-founder of VantegrateLinkedIn

SOQL definition

SOQL (Salesforce Object Query Language) is Salesforce's own query language, used to read data stored in the platform's objects. Its syntax resembles SQL (it uses SELECT ... FROM ... WHERE), but it operates on Salesforce objects (standard and custom) instead of tables in a traditional database, and it returns records that the code then processes.

Unlike SQL, SOQL only retrieves data: it has no INSERT, UPDATE or DELETE (those operations are done with DML in Apex), it does not allow SELECT \* (you have to name each field) and it does not do arbitrary joins; instead, it navigates the relationships already defined between objects. It is one of the core tools for anyone who builds on the platform, part of the craft covered by the Salesforce developers team.

What SOQL is used for

Every time a screen, an automation or a piece of code in Salesforce needs to fetch records (the accounts in a region, a sales rep's open opportunities, unresolved cases), there is almost always a SOQL query underneath. It is written inside Apex, in Lightning Web Components, in integration tools or directly in the Developer Console to inspect data. It is the bridge between business logic and the information stored in the org.

A typical query selects the name, amount and stage of opportunities whose amount exceeds a certain threshold, sorted by close date. The big difference from a classic relational database is how it handles relationships between objects: instead of building joins, SOQL takes advantage of the relationships that already exist in the data model. To go up from a child record to its parent, you use dot notation (the contact accesses fields from its account), and to go down to the children, you use a relationship subquery (from an account, you request its contacts). This makes queries more readable, but it also means they are tied to the schema defined on the platform.

Why it matters for a business

Although it sounds like a technical detail, SOQL has a direct impact on what the user experiences. A well-written query is the difference between a report that loads instantly and one that lags or fails. In Argentina and Latin America, where it is common to have orgs with hundreds of thousands of records (customers, invoices, support cases), the cost of poorly designed queries shows: slow screens, automations that break and nightly processes that do not finish on time.

There is a concrete reason behind this. Salesforce is a multitenant architecture (many companies share the same infrastructure), so it enforces governor limits: caps on how many SOQL queries and how many records a transaction can handle. If the code exceeds them, the operation is interrupted. That is why writing efficient SOQL is not a luxury: it is what keeps the platform stable for everyone.

SOQL vs SQL: how they differ

They come from similar worlds, but they are not interchangeable. This table summarizes the key differences:

AspectSOQLSQL
What it doesOnly reads data (queries)Reads and modifies (full CRUD)
What it operates onSalesforce objectsDatabase tables
SelectionYou must name each fieldCan return all columns
RelationshipsNavigates predefined relationshipsArbitrary joins between tables
LimitsSubject to governor limitsDepends on the database engine

Developers coming from SQL pick up the basics of SOQL quickly, but they stumble over what is missing: there is no way to fetch all columns with a wildcard, there are no free-form joins and you always have to think about the limits.

Common mistakes to avoid

  • Queries inside a loop: repeating a query for each record in a list quickly exhausts the limits. The rule is to bulkify: a single query that fetches everything needed at once.
  • Fetching more fields or records than necessary: requesting fields that are not used or not filtering inflates consumption and latency. It pays to narrow results with conditions and, where applicable, with a row limit.
  • Not filtering on indexed fields: querying non-indexed fields on large tables forces a full scan, which triggers timeout errors in high-volume orgs.
  • Confusing SOQL with SQL: attempting a column wildcard or a join that does not exist in the model ends in a syntax error.

A concrete example

A Consumer Goods distributor in Buenos Aires wants to show each sales rep their accounts with an outstanding balance. Instead of querying account by account (which, with 5,000 customers, would blow through the limits), the developers build a single query that filters by owner and by collections status, sorts by amount and displays it in a component. The result: the screen loads in seconds and the process scales without touching the platform's caps. That decision, invisible to the end user, is the kind of SOQL best practice that separates a robust implementation from one that breaks when the data grows.

Share
Frequently asked questions

FAQs about SOQL

What is SOQL?

SOQL (Salesforce Object Query Language) is Salesforce's query language, used to read data from the platform's objects, both standard and custom. Its syntax resembles SQL, with SELECT, FROM and WHERE, but it only retrieves records: it does not insert, update or delete data. It is used inside Apex, in Lightning components and in integrations to fetch the information each process or screen needs.

What is the difference between SOQL and SQL?

The main difference is scope. SQL is a complete language that reads and modifies data (INSERT, UPDATE, DELETE) on database tables, and it allows arbitrary joins and fetching all columns with a wildcard. SOQL only queries data on Salesforce objects, requires you to name each field, does not support that wildcard or free-form joins (it navigates relationships already defined in the model) and is subject to the platform's limits. Data changes in Salesforce are made with DML, not with SOQL.

Can you use SOQL to create or delete records?

No. SOQL is read-only: it only retrieves existing records. To create, update or delete data in Salesforce, you use DML (Data Manipulation Language) operations inside Apex, such as insert, update and delete. It is a deliberate separation in the platform: SOQL queries and DML modifies, and both respect the org's permissions and limits.

Why is there a limit on the number of SOQL queries?

Because Salesforce is a multitenant architecture where many companies share the same infrastructure. So that heavy usage by one org does not degrade the service for the rest, the platform applies governor limits, which cap how many SOQL queries and how many records a transaction can process. If the code exceeds those caps, the operation is interrupted. That is why writing efficient queries, with no SOQL inside loops, is a fundamental practice.

Where do you write a SOQL query?

It is written mainly inside Apex code, in Lightning Web Components, in integration tools that use the API and in the Developer Console or the Query Editor to inspect data directly. In every case, the query returns records that the code then processes, displays on screen or sends to another system.

We bring this to your Salesforce

Salesforce implementation, integration and support for LatAm companies, focused on the team actually using it instead of going back to spreadsheets. Tell us where your org stands.

Keep exploring

Related terms

From the glossary

Related questions

We solve it with

Salesforce

Salesforce implementation, integration and support for LatAm companies, focused on real team adoption.

How Salesforce solves it
The full suite
Now that you know what it is, see how it gets solved

Five AI products that work on top of the CRM you already use. They don't replace your system: they add the layer you do by hand today.