Governor Limits in
Salesforce
- Sai Manasa S
What is a Governor Limit ?
Governor limits are runtime limits enforced by the Apex runtime engine to ensure that
code does not throw errors.
As Apex runs in a shared, multi-tenant environment, the Apex runtime engine strictly
enforces a number of limits to ensure that code does not monopolize shared resources.
Resources such as CPU, processor, and bandwidth are shared by Apex on the
Salesforce server.
*Capping the resources used by individual user or program.
What do Governor Limits do ?
1. Monitor and manage platform resources such as memory, database
resources, etc.
2. Enable multi-tenancy by ensuring the resources are available for all tenants
on the platform.
3. Can issue program-terminating runtime exceptions when the limit is
exceeded.
4. Typically reset per transaction.
5. Subject to change from release to release.
Governor Limits Basically Cover
1. Memory.
2. Database Resources.
3. A number of script statements.
4. A number of records were processed
Types Of Governor Limits
1. Per-Transaction Apex Limits: These limits count for each Apex transaction. For Batch Apex, these
limits are reset for each execution of a batch of records in the execute method.
2. Per Transaction Certified Managed Package Limits: If a managed package developed by a
Salesforce ISV has passed security review, they are provided with generally higher per-transaction
limits.
3. Lightning Platform Apex Limit: These limits aren’t specific to an Apex Transaction and are enforced
by the Lightning platform.
4. Static Apex Limit: Apex Limits that are applied across all transactions.
5. Size-Specific Apex Limit: Apex Limits related to the size of code.
6. Miscellaneous Apex Limit: Other Limits!
Why Are SalesForce Governor Limits Important ?
Governor Limits are a concept that all Salesforce Developers must grasp.
They will fundamentally shape the way that you architect Salesforce solutions,
as well as how the code is written.
If a Salesforce Governor Limit is hit, the associated governor issues a runtime
exception that cannot be handled. In other words, your code breaks and won’t
work.
Governor Limit Best Practices
It is good to avoid giving soql and DMLs in for loop.
SOQL Queries Limit is 100
Example :
For (integer i = 0; i<= 100; i++){
Integer countofacccounts = [ SELECT count() From Account];
}
If we execute this code .. We will get an Error… like
Execute Anonymous Error – Too Many SOQL Queries
DML Statement Limit 150
DML LIMIT FIX
Can We Override Governor Limit?
Yes, we can Override by using Batch Apex.
Database. Batchable interface contains 3 methods that must be implemented
1. Start()
2. Execute()
3. finish()
NOTE–The order of execution of batches is not guaranteed.
Interview Questions Related To Governor Limits :
1. What is a Governor Limit?
1. What are governor limits in salesforce and why are they important?
2. How does the DML statement limit affect data operations in Salesforce? Provide
an example scenario where this limit could be reached.
3. What is the significance of the SOQL query limit in Salesforce? How can you
work within this limit when retrieving records?
4. Explain the purpose of the Apex CPU time limit in Salesforce and its impact on
code execution.
Question And Answers
1. What is a governor limit in Salesforce?
Answer- Governor limits are runtime limits enforced by the
Apex runtime engine to ensure that code does not throw
errors.
What are governor limits in Salesforce, and why are they important?
Answer: Governor limits in Salesforce are runtime limits that control the amount of resources, such as CPU
time, memory, and database operations, that can be utilized by individual transactions, code executions, and
API requests. They are important because they ensure fair resource allocation, promote efficient code
execution, and maintain the overall stability and performance of the Salesforce platform.