
Governor limits in Salesforce are essential rules that ensure the platform’s multi-tenant architecture runs smoothly and efficiently. Whether you’re an administrator, developer, or Salesforce consultant, understanding these limits is crucial for writing scalable and optimized Apex code.
In this guide, we’ll cover:
-
What governor limits are in Salesforce
-
Types of governor limits
-
Real-life examples
-
Best practices to avoid hitting these limits
-
Latest updates and limits in 2025
What Are Governor Limits in Salesforce?
Governor limits are runtime constraints enforced by Salesforce to prevent a single tenant (user or org) from overconsuming shared resources. These limits apply to:
-
Apex code execution
-
Database operations (SOQL, SOSL, DML)
-
Callouts
-
CPU time
-
Heap size
💡 Why it matters: Salesforce runs on a shared infrastructure. Without these limits, one org’s inefficient code could affect others.
Why Salesforce Governor Limits Exist
Salesforce uses a multi-tenant architecture, where multiple customers share the same server resources. To maintain performance and prevent abuse, Salesforce enforces strict runtime limits. These act as protective boundaries and promote better coding practices.
Key Benefits:
-
Fair resource allocation
-
System stability
-
Encourages optimized code
-
Prevents infinite loops and excessive resource consumption
Types of Governor Limits in Salesforce (2025 Updated)
Here’s a comprehensive table outlining the most important governor limits (based on latest updates):
Limit Type | Synchronous Limit | Asynchronous Limit |
---|---|---|
Total SOQL queries | 100 | 200 |
Records retrieved by SOQL | 50,000 | 50,000 |
SOSL queries | 20 | 20 |
DML statements | 150 | 150 |
Records processed by DML | 10,000 | 10,000 |
CPU time | 10,000 ms | 60,000 ms |
Heap size | 6 MB | 12 MB |
Callouts (HTTP/Web Services) | 100 | 100 |
Maximum trigger recursion depth | 16 | 16 |
Common Scenarios Where Governor Limits Break Code
-
Too Many SOQL Queries
-
Problem: Query inside a loop
-
Fix: Move SOQL out of loops, use collections like Map or Set
-
-
Too Many DML Statements
-
Problem: Performing DML inside loops
-
Fix: Bulkify DML using Lists
-
-
CPU Time Limit Exceeded
-
Problem: Complex logic or unoptimized loops
-
Fix: Reduce operations, use asynchronous Apex
-
-
Heap Size Limit
-
Problem: Loading too much data into memory
-
Fix: Optimize queries, reduce variables or use
Limits.getHeapSize()
-
Best Practices to Avoid Governor Limits
Practice | Explanation |
---|---|
Bulkify your code | Handle multiple records in one transaction using Lists/Maps |
Avoid SOQL/DML in loops | Move them outside loops to prevent repetitive usage |
Use asynchronous processing | Use Queueable, Future, or Batch Apex for heavy operations |
Monitor limits | Use Limits class (Limits.getQueries() , getDMLStatements() ) |
Write efficient triggers | Use trigger frameworks to control logic execution |
Optimize logic | Refactor nested conditions and remove unnecessary operations |
Use Database.SavePoint |
Manage partial rollbacks in complex transactions |
Sample Apex Code to Monitor Governor Limits
Advanced Tip: Certified Managed Packages
If you’re an ISV (Independent Software Vendor) using certified packages, you get separate governor limits, which do not count toward your org-wide limits. This helps in building scalable enterprise apps.
Governor Limits Interview Questions
Want to prepare for interviews? Here are common questions asked:
-
What are governor limits in Salesforce?
-
Why do they exist?
-
How do you avoid hitting SOQL limits?
-
Explain CPU time limit.
-
What is the difference between synchronous and asynchronous limits?
-
How can Batch Apex help with governor limits?
Comparison with Top Ranking Competitors
Site | Missing Features | Our Advantage |
---|---|---|
Apex Hours | No detailed examples | We provide real Apex snippets & fixes |
Intellipaat | Lacks 2025 update | We include latest governor limits |
Simplilearn | Basic definitions only | We give in-depth use cases + code |
Salesforce Ben | Skips best practices table | Included structured action tables |
Codestreets | Overly long and lacks visuals | We’re concise, formatted, and scannable |
You may like : Lwc Interview Questions
FAQs About Governor Limits in Salesforce
Q1. Can governor limits be increased in Salesforce?
No, governor limits are enforced by the platform and cannot be increased.
Q2. What happens if a governor limit is exceeded?
Salesforce throws a runtime exception and stops the transaction immediately.
Q3. How can I debug governor limit issues?
Use the Developer Console, Limits
class, and debug logs to monitor usage.
Q4. What tools can help avoid governor limits?
-
Salesforce Developer Console
-
Debug Logs
-
Limits
class -
Apex Test Execution logs
Q5. Which governor limit is most frequently hit?
SOQL Query limit and DML statements are the most common, especially in poorly written triggers.
Conclusion
Mastering governor limits in Salesforce is critical for writing high-performance, scalable code. Whether you’re building triggers, batch classes, or integrations, knowing your limits (literally!) can save your org from unexpected failures and performance issues. Keep this guide bookmarked — and follow these best practices to stay under limits, over deliver, and out-rank the competition!