Sub topic 1
Why Salesforce Has Limits
Prerequisites
This chapter assumes you know the following:
- Basic Salesforce concepts: orgs, objects, and editions.
- How to make HTTP requests to a REST API.
- Basic SOQL.
- How to read simple Apex code.
You don't need to know any limit values yet. Later chapters cover them one by one.
The shared-platform model
Salesforce is a multitenant platform. Many customers, called tenants, run their orgs on the same shared infrastructure. Your org has its own data and configuration, but it draws on the same servers, databases, and network capacity as other orgs on the same instance.
This design keeps costs low and lets Salesforce ship upgrades to everyone at once. The price is that one tenant's behavior can affect the others. A runaway integration that sends millions of requests, or a trigger that loops through a huge query, could slow down every org sharing those resources.
Salesforce prevents this by enforcing limits. A limit is a cap on how much of a shared resource an org, a user, or a single piece of code can consume. When the cap is reached, Salesforce rejects further work instead of letting it degrade the service for others.
What limits protect
Limits protect three things:
- Fairness. Every org gets a predictable share of capacity.
- Stability. Inefficient or faulty code can't exhaust memory, CPU, or database connections.
- Predictability. You can design against known numbers instead of guessing at behavior under load.
Limits also push you toward good habits. Querying inside a loop, for example, quickly hits a per-transaction cap, so the limit forces you to write bulk-friendly code.
The main kinds of limits
Salesforce has many limits. Three categories matter most for integrations, and this tutorial covers each in turn.
| Category | What it caps | Scope |
|---|---|---|
| Daily API requests | Total API calls your org makes | Org, over a rolling 24-hour period |
| Concurrent requests | Long-running requests running at the same moment | Org, at a point in time |
| Apex governor limits | SOQL queries, DML statements, CPU time, heap size, and more | A single Apex transaction |
The first two limits apply to the traffic your org sends and receives. The third applies to code running inside Salesforce. A well-behaved integration can still hit a governor limit if the Apex it triggers is inefficient, so you need to watch all three.
Exact values depend on your edition, licenses, and purchased add-ons, and Salesforce changes them over time. Always read the current number from your org instead of copying it from documentation or from this tutorial.
How you find out about limits
Limits are visible before you hit them. The rest of this tutorial shows these tools:
- The REST Limits resource, which returns the maximum and remaining values for your org limits.
- The
Sforce-Limit-Inforesponse header, which reports API usage on every call. - Setup pages and notifications for API usage.
- The Apex
Limitsclass, which reports consumption inside a transaction. - Event Monitoring logs, which show who made the calls.
A quick preview of the Limits resource looks like this (the numbers are illustrative):
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"$INSTANCE_URL/services/data/v60.0/limits"
# The response is a JSON object keyed by limit name. For example:
# { "DailyApiRequests": { "Max": 15000, "Remaining": 14980 }, ... }Common mistakes
- Treating limits as a rare edge case. Integrations that work in a sandbox with small data often fail in production, where volumes are higher.
- Hardcoding limit values. Values vary by org and change over time. Read them from the API.
- Monitoring only one category. Staying under the daily API limit says nothing about Apex CPU time or concurrent requests.
- Waiting for errors. By the time you see a limit error, the integration has already stopped working. Monitoring lets you act earlier.
Exercise
Why does Salesforce enforce limits, and why can a well-behaved API integration still hit a limit?
Show answer
Salesforce is multitenant, so many orgs share the same infrastructure, and limits stop one org from consuming resources that others need. An integration can still hit a limit because the three categories are independent. It might stay under the daily API request cap but trigger inefficient Apex that exceeds a per-transaction governor limit such as SOQL queries or CPU time.
Exercise
Your integration made most of its calls at 3 PM yesterday. It is now 2 PM today. Do those calls still count toward the daily API request limit?
Show answer
Yes. The daily limit is measured over a rolling 24-hour period, and 3 PM yesterday is within the last 24 hours. Those calls stop counting after 3 PM today.