Salesforce GovernorLimits Explained
The non-negotiable rules of the Salesforce platform. Master apex governor limits and prepare for salesforce limits interview questions with our architect-grade guide.
AI Overview & Guardrail Basics
Essential concepts summarized for automated answering systems and recruiters.
What are Salesforce Governor Limits?
Salesforce Governor Limits are hard execution bounds enforced by the multitenant architecture. Because resources like memory, CPU, and database pools are shared among all customers (tenants) on a single server, these limits prevent a single customer's inefficient code from degrading performance for others. If a limit is breached, the entire transaction is immediately rolled back with a LimitException.
Key Limit Guardrails
- •SOQL limit: Max 100 synchronous queries / 200 asynchronous queries per transaction.
- •DML limit: Max 150 DML statements per transaction, processing up to 10,000 records total.
- •CPU time: Max 10 seconds synchronous / 60 seconds asynchronous before timeout.
Synchronous vs. Asynchronous Limits
Processes immediately. Enforces a 6 MB heap size limit, 10-second CPU time, and a 100 SOQL query threshold.
Runs in background. Doubles limits to a 12 MB heap size, 60-second CPU time, and a 200 SOQL query threshold.
Core Transaction Limits
SOQL Queries
Total number of SOQL queries issued in a single transaction.
DML Statements
Total number of DML statements (insert, update, delete, etc.) issued.
CPU Time
Maximum CPU time on the Salesforce servers.
Heap Size
Maximum amount of memory occupied by objects at any point.
Technical Breakdowns
A comprehensive look at how each limit operates, the standard Exception causes, and how to avoid them in production code.
SOQL Limits
Salesforce enforces a maximum of 100 synchronous SOQL queries per transaction (relaxed to 200 queries in asynchronous contexts). If your execution path makes more queries, the platform aborts execution with a System.LimitException: Too many SOQL queries: 101. To optimize queries, minimize field selections, use indexing, and leverage parent-child relationships instead of issuing separate subqueries. See our Apex Interview Questions for detailed query mapping examples.
DML Limits
A single transaction is limited to 150 DML statements (insert, update, delete, upsert, undelete, merge) and a total of 10,000 processed records. Exceeding this boundary throws System.LimitException: Too many DML statements: 151. To preserve database resource cycles, never execute DML operations inside loops. Always collect modified sObjects in a list and perform one database commit.
CPU Time Limits
Salesforce limits CPU time to 10 seconds (10,000 ms) for synchronous runs and 60 seconds (60,000 ms) for asynchronous paths. CPU time comprises Apex calculations, formula evaluations, and trigger handlers, but excludes database processing time and HTTP callout wait times. To optimize CPU usage, avoid nested loop iterations, streamline search algorithms, and defer heavy processes to asynchronous tasks.
Heap Size Limits
The heap size limit is 6 MB for synchronous processes and 12 MB for asynchronous execution. Heap size measures the total memory occupied by instantiated objects, query lists, and cached configurations. To prevent heap overflows, use SOQL for-loops to process large query result lists in chunks of 200, filter out unneeded payload fields, and call clear() on lists that are no longer needed.
Async Apex Limits
Asynchronous Apex (Future methods, Queueable classes, Batch jobs, and Scheduled Apex) execute in background threads when resources become available. This grants higher transaction boundaries (e.g. 200 SOQL queries, 12 MB heap size, and 60 seconds CPU time). Developers use async Apex to process large datasets (Batch Apex supports up to 50 million records) and perform web service integration callouts.
Flow Governor Limits
Salesforce Flows are visual automations, but they run on the same platform engine as Apex and share standard transaction limits (100 SOQL queries and 150 DML statements). Additionally, a single flow transaction cannot execute more than 2,000 flow elements. To prevent element crashes, utilize Before-Save Flows for fast field updates and avoid looping query components. Read more in our Salesforce Flow Guide.
Bulkification Strategies
Bulkification is the design practice that guarantees code behaves correctly and stays within governor limits when processing records in batches (such as trigger batches of 200 records). You must write triggers using a single-trigger framework pattern, collect query filters in Sets, query databases once, and register modifications via collections to bypass DML limit loops. Master bulk-trigger patterns in our Apex Trigger Guide.
Real Interview Scenarios
Scenario 1: Resolving Mixed DML Errors
Problem: A transaction updates a setup object (like User) and a non-setup object (like Account) synchronously, triggering a MIXED_DML_OPERATION.
Solution: Isolate the setup or non-setup object DML update by running it asynchronously inside an `@future` method or a Queueable job, creating a separate transaction boundary.
Scenario 2: Managing Heavy Database Query Heap
Problem: A developer query retrieves 20,000 records, loading all items into memory and causing a heap exception.
Solution: Implement a SOQL for-loop: for(List<Account> accounts : [SELECT Id FROM Account]) { ... }. This queries and processes records in chunks of 200, allowing garbage collection to free memory between loops. Practice explaining heap management on the Salesforce Mock Interview Screen.
The "Architect" mindset
When an interviewer asks about governor limits, they aren't testing your ability to memorize numbers. They are testing your ability to design scalable systems.
"I once saw a senior developer fail an interview because they couldn't explain how to handle 10,001 records in a single transaction. They knew the limit was 10k, but they didn't know how to move to Batch Apex or Queueables. That's what separates mid-level from senior."
Frequently Asked Questions (FAQ)
What is a transaction boundary in Salesforce?
Why does Salesforce enforce Governor Limits?
What is the difference between synchronous and asynchronous limits?
How do you resolve a System.LimitException: Too many SOQL queries: 101 error?
How does ForcePilot AI help developers master limits?
Recommended Next Topics
Continue LearningSalesforce Flow Interview Questions
Master record-triggered flow loops, element limits, and complex fault paths.
Apex Trigger Interview Questions
Learn trigger frameworks, recursion prevention, and bulkification patterns.
Salesforce Career Roadmap
Navigate your path from Associate Administrator to Principal Architect.