What This Error Means
A System Limit Exception occurs when one of these governor limits is exceeded during the execution of a transaction. These limits are enforced by Salesforce to protect shared resources in a multitenant environment. If your Apex code, Flow, or other automated process consumes too many resources, such as too many queries or too many DML statements, Salesforce stops the execution and throws this error.
Common Error Messages
You may see messages like,
- System.LimitException: Too many SOQL queries: 101
- System.LimitException: Too many DML statements: 151
- System.LimitException: Apex CPU time limit exceeded
- System.LimitException: Heap size too large
- System.LimitException: Too many query rows: 50001
These indicate that your logic has crossed one of Salesforce’s runtime limits and can’t complete the transaction.
Where This Error Commonly Occurs
This exception can appear in
- Apex Triggers processing large or bulk records
- Flows or Process Builder automation with many operations
- Batch Apex or Queueable Apex handling large datasets
- Test classes executing complex logic
- Anywhere in code where limits are reached due to inefficient design
These indicate that your logic has crossed one of Salesforce’s runtime limits and can’t complete the transaction.
Why This Error Happens?
Salesforce imposes limits on each transaction to keep the platform stable. Some of the most common limits include,
SOQL Query Limits
There is a governor that limits how many SOQL queries can be issued in a single transaction (e.g. 100 for synchronous Apex). The exception Too many SOQL queries: 101 is thrown upon surpassing the limit.
DML Statement Limits
If your code performs more than 150 DML actions in one transaction, Salesforce won’t allow it.
CPU Time Limits
Each transaction has a maximum execution (CPU) time. If the logic takes too long, it ends with the Apex CPU time limit exceeded.
Heap Size Limits
Storing too much data in memory can lead to heap size too large errors. Other limits, such as SOSL queries or callouts per transaction, can also surface this exception.
Common Causes
- SOQL or SOSL queries inside loops
- DML operations inside loops
- Heavy calculations or recursive logic
- Multiple automation tools firing together
- Poor bulkification in Apex or Flows
How to Fix System Limit Exceptions
Step 1. Avoid Queries/DML Inside Loops
Move
SOQL and DML operations out of loops. Collect records first using collections (List, Set, Map), then perform queries and updates.
Step 2. Bulkify Your Code
Design triggers and Apex to handle multiple records at once, processing collections rather than single records.
Step 3. Use Asynchronous Processing
If processing large volumes of data, break the work into asynchronous transactions with
- Batch Apex
- Queueable Apex
- Future methods
Each runs in its own context with separate limits.
Step 4. Reduce Memory Usage
Avoid storing large objects or unnecessary records in memory. Only keep what’s essential in variables.
Step 5. Optimise Flows and Automation
Review Flows or Process Builder automations that repeatedly query or update records. Restrict operations within loops and use efficient criteria.
Best Practices to Prevent This Error
- Always bulkify Apex and Flows
- Avoid SOQL/DML inside loops
- Test with large data volumes
- Use asynchronous processing for heavy logic
- Regularly review governor limits during development
Who Should Handle This Error