Sub topic 2
The Main Kinds of Limits
This chapter assumes you know what a Salesforce org is, can send HTTP requests to a REST API, and can read basic Apex and SOQL. It sorts Salesforce limits into three groups so you know which one you are dealing with when something fails.
Why categories matter
Salesforce is multitenant, so many orgs share the same infrastructure. Limits keep one org from starving the others. Different limits protect different resources, and each one is measured, reported, and fixed in a different way. If you mix them up, you will monitor the wrong number or apply the wrong fix.
This tutorial focuses on three categories:
- Daily API request limits.
- Concurrent long-running request limits.
- Apex governor limits.
Daily API request limit
This limit caps the number of API calls an org can make in a rolling 24-hour period. It is an org-wide total. Every integration, script, and connected app draws from the same pool. The size of the pool depends on your edition and license count.
When the pool runs out, further API calls fail until older calls age out of the 24-hour window. Because it is a rolling window, usage does not reset at midnight.
Concurrent long-running request limits
This limit caps how many long-running requests can be in progress at the same moment. The number of calls over a day does not matter here. Salesforce counts requests that run longer than a set time and are still open at once. Exceeding the cap blocks new long-running requests until some of the running ones finish.
A typical cause is many parallel integration threads that each trigger slow queries or heavy processing.
Apex governor limits
Governor limits apply inside one Apex transaction. They cap resources such as SOQL queries, DML statements, CPU time, and heap size. A transaction that goes over a limit throws an uncatchable exception and rolls back.
These limits are unrelated to the API call count. A single API call can run Apex that breaks a governor limit, and an API call that runs no Apex cannot.
Comparing the three
| Category | Scope | Measured over | Typical symptom |
|---|---|---|---|
| Daily API requests | Whole org | Rolling 24 hours | `REQUEST_LIMIT_EXCEEDED` on API calls |
| Concurrent long-running requests | Whole org | The current moment | Requests rejected while others are still running |
| Apex governor limits | One transaction | A single execution | Limit exception, transaction rolled back |
Where to look for each one
Each category has its own monitoring tool, covered in later chapters.
- Daily API requests: the REST Limits resource, the
Sforce-Limit-Infoheader, and Setup pages. - Concurrent requests: error responses and Event Monitoring logs.
- Governor limits: the Apex
Limitsclass.
As a first look, the Apex Limits class shows both the amount used and the ceiling for the current transaction:
System.debug('SOQL queries: ' + Limits.getQueries() + '/' + Limits.getLimitQueries());
System.debug('DML statements: ' + Limits.getDmlStatements() + '/' + Limits.getLimitDmlStatements());Common mistakes
- Treating the daily limit as a calendar-day quota that resets at midnight. It is a rolling window.
- Assuming that a low daily count means no limit risk. Concurrency and governor limits can still fail your calls.
- Trying to fix a governor limit error by reducing the number of API calls. The fix belongs in the Apex code, for example by bulkifying queries.
Exercise
An integration sends 500 API calls in one hour, well under your org's daily limit. Some calls still fail because they run Apex that issues too many SOQL queries. Which category of limit is involved, and where would you fix it?
Show answer
This is an Apex governor limit, which applies per transaction. The daily API limit is not the cause, since only 500 calls were made. Fix it in the Apex code, for example by moving SOQL queries out of loops so each transaction uses fewer queries.