Secret Strategies to Conquer Governor Limits and Revolutionize Your Development Game!

Embarking on the journey of Salesforce development is an exhilarating experience, but every developer encounters a formidable challenge along the way – the infamous Governor Limits. Today, we delve into the world of Salesforce Governor Limits, understanding why they stand as the quintessential challenge for developers.

In the realm of Salesforce, Governor Limits present a unique hurdle that demands careful consideration from developers. These limits are not mere guidelines; they are thresholds that, if exceeded, prompt Salesforce to throw a runtime exception, leaving developers in a predicament. This issue cannot be handled conventionally, making it a critical aspect of application development in the Salesforce ecosystem. As a Salesforce developer, the onus is on you to navigate these limits with finesse. A single misstep, and your Apex code could breach the boundaries, triggering a cascade of issues. In this intricate dance between development and constraints, precision and caution become the guiding principles.

What are Governor Limits and how How Salesforce Keeps Things Fair!

Ever wondered how Salesforce makes sure everyone gets a fair share of the data pie? Well, that’s where Governor Limits come into play. In simple terms, these limits control how much information or records can be stored in the big database Salesforce uses. Picture it like a shared space – since lots of people use it, we need rules to make sure no one hogs all the resources. It’s like a friendly traffic cop for data, ensuring things run smoothly and everyone gets what they need. Let’s dive into the basics of Salesforce’s Governor Limits and see how they help keep things fair in the world of data storage.

Types of Governor Limits in Salesforce

In Salesforce development, there are various types of limits that shape the way we build and execute processes. Let’s take a look at different categories of these limits:

1. Per-Transaction Apex Limits

These limits apply to every Apex transaction. In Batch Apex, these limits reset with each execution of a batch in the execute method. The table outlines limits for synchronous Apex and asynchronous Apex (Batch Apex and future methods) when they differ. If the limits are the same for both, the table highlights a single limit for both synchronous and asynchronous Apex.

Description Synchronous Limit Asynchronous Limit
Total number of SOQL queries issued 100 200
Total number of records retrieved by SOQL queries 50000 50000
Total number of records retrieved by Database.getQueryLocator 10000 10000
Total number of SOSL queries issued 20 20
Total number of records retrieved by a single SOSL query 2000 2000
Total number of DML statements issued 150 150
Total number of records processed as a result of DML statementsApproval.process, or database.emptyRecycleBin 10000 10000
Total stack depth for any Apex invocation that recursively fires triggers due to insertupdate, or delete statements 16 16
Total number of callouts (HTTP requests or web services calls) in a transaction 100 100
Maximum cumulative timeout for all callouts (HTTP requests or Web services calls) in a transaction 120 seconds 120 seconds
Maximum number of methods with the future annotation allowed per Apex invocation 50 0 in batch and future contexts;
50 in queueable context
Maximum number of Apex jobs added to the queue with System.enqueueJob 50 1
Total number of sendEmail methods allowed 10 10
Total heap size 6 MB 12 MB
Maximum CPU time on the Salesforce servers 10000 milliseconds 60000
Maximum execution time for each Apex transaction 10 minutes 10 minutes
Maximum number of push notification method calls allowed per Apex transaction 10 10
Maximum number of push notifications that can be sent in each push notification method call 2000 2000
Maximum number of EventBus.publish calls for platform events configured to publish immediately 150 150
2. Per-Transaction Certified Managed Package Limits

Certified managed packages—managed packages that have passed the security review for AppExchange—get their own set of limits for most per-transaction limits. Salesforce ISV Partners develop certified managed packages, which are installed in your org from AppExchange and have unique namespaces.This table lists the cumulative cross-namespace limits.

Description Cumulative Cross-Namespace Limit
Total number of SOQL queries issued 1100
Total number of records retrieved by Database.getQueryLocator 110000
Total number of SOSL queries issued 220
Total number of DML statements issued 1,650
Total number of callouts (HTTP requests or web services calls) in a transaction 1,100
Total number of sendEmail methods allowed 110
3. Lightning Platform Apex Limits

The limits in this table aren’t specific to an Apex transaction; Lightning Platform enforces these limits.

Description Limit
The maximum number of asynchronous Apex method executions (batch Apex, future methods, Queueable Apex, and scheduled Apex) per a 24-hour period 250,000 or the number of user licenses in your org multiplied by 200, whichever is greater
Number of synchronous concurrent transactions for long-running transactions that last longer than 5 seconds for each org. 10
Maximum number of Apex classes scheduled concurrently 100. In Developer Edition orgs, the limit is 5.
Maximum number of batch Apex jobs in the Apex flex queue that are in Holding status 100
Maximum number of batch Apex jobs queued or active concurrently 5
Maximum number of batch Apex job start method concurrent executions 1
Maximum number of batch jobs that can be submitted in a running test 5
Maximum number of test classes that can be queued per 24-hour period (production orgs other than Developer Edition) The greater of 500 or 10 multiplied by the number of test classes in the org
Maximum number of test classes that can be queued per 24-hour period (sandbox and Developer Edition orgs) The greater of 500 or 20 multiplied by the number of test classes in the org
4. Static Apex Limits

These limits are consistent across all transactions, providing a standard set of boundaries for code execution.

Description Limit
Default timeout of callouts (HTTP requests or Web services calls) in a transaction 10 seconds
Maximum size of callout request or response (HTTP request or Web services call) 6 MB for synchronous Apex or 12 MB for asynchronous Apex
Maximum SOQL query run time before Salesforce cancels the transaction 120 seconds
Maximum number of class and trigger code units in a deployment of Apex 7500
Apex trigger batch size 200
For loop list batch size 200
Maximum number of records returned for a Batch Apex query in Database.QueryLocator 50 million
5. Size-Specific Apex Limits

These limits are associated with the size of the code, influencing how much data or logic can be accommodated within a given context.

Description Limit
Maximum number of characters for a class 1 million
Maximum number of characters for a trigger 1 million
Maximum amount of code used by all Apex code in an org 6 MB
Method size limit 65,535 bytecode instructions in compiled form
6. Miscellaneous Apex Limits:

Additional limits that play a role in various aspects of Apex development.

7. Email Limits:

Governs the number and frequency of emails that can be sent from Salesforce.

8. Push Notification Limits

Dictates the thresholds for push notifications, ensuring a balanced and effective communication system.

Understanding these different types of limits is essential for developers, guiding them to create efficient and effective solutions within the constraints of the Salesforce environment.

Advantages of Governor Limits in Salesforce

Governor limits in Salesforce offer several advantages that contribute to the overall stability, performance, and fairness of the platform. Here are some key advantages:

      1. Preventing Resource Abuse: Governor limits prevent the abuse of resources, ensuring that no single transaction or process monopolizes the system’s resources, such as CPU time, memory, or database resources.
      2. Avoiding Performance Bottlenecks: By imposing constraints on the amount of resources a transaction can consume, governor limits help prevent performance bottlenecks, ensuring the stability of the Salesforce platform for all users.
      3. Maintaining Fairness: Governor limits promote fairness by preventing users or processes from taking up an unfair share of resources. This ensures that all users have equal access to the platform’s capabilities.
      4. Encouraging Efficient Coding Practices: Developers are encouraged to write efficient code and adopt best practices to stay within the governor limits. This optimization leads to better overall performance and responsiveness of Salesforce applications.
      5. Runtime Exception Handling: If a transaction exceeds its allocated governor limits, Salesforce throws a runtime exception that cannot be handled conventionally. While this may seem like a limitation, it serves as a safety mechanism to prevent runaway processes and maintain system integrity.
      6. Controlling Usage Costs: Governor limits help control resource usage, which is crucial in a cloud-based environment where resource consumption often correlates with costs. By preventing excessive resource usage, governor limits contribute to cost control.
      7. Promoting Bulk Operations: Governor limits encourage developers to design bulk operations, where multiple records are processed in a single transaction. This approach minimizes the impact on governor limits and improves overall efficiency.
      8. Ensuring Scalability: By enforcing limits, Salesforce ensures the scalability of its platform. Preventing resource-intensive processes from dominating the system allows Salesforce to efficiently scale to accommodate a growing user base.
How to overcome governor limits in Salesforce

Overcoming governor limits in Salesforce requires a combination of strategic development practices, optimization techniques, and a thorough understanding of the limits imposed by the platform. Here are several strategies to help you navigate and work within the confines of Salesforce governor limits:

  1. Bulk Processing:

    Leverage bulk processing to handle large volumes of data in a single transaction. Bulk operations are more efficient and help you stay within the limits by reducing the number of transactions needed.

  2. Query and Aggregate Efficiently:

    Optimize your queries and aggregations to minimize the number of SOQL queries and the amount of data retrieved. Utilize selective queries to fetch only the necessary records.

  3. Use Collections Wisely:

    Make efficient use of collections (lists, sets, and maps) to store and manipulate data. Minimize the iteration over large datasets to avoid hitting iteration limits.

  4. Implement Asynchronous Processing:

    Offload resource-intensive tasks to asynchronous processes, such as batch jobs or future methods. As a result, asynchronous processing allows you to handle large volumes of data without impacting the user experience.

  5. Reduce Formula Fields:

    Limit the use of complex formula fields, especially in queries or reports, as they may consume more CPU time. Consider optimizing or simplifying formulas where possible.

  6. Avoid Nested Queries and Loops:

    Refrain from using nested queries and loops excessively, as they can quickly accumulate resource usage. Opt for alternative approaches like aggregations and relationships.

  7. Implement Pagination:

    When managing extensive datasets, incorporate pagination to restrict the retrieval of records within a single query, effectively avoiding exceeding query row limits.

  8. Optimize Code Logic:

    Review and optimize your Apex code logic to minimize CPU time consumption. Identify and eliminate redundant or unnecessary operations that may contribute to exceeding governor limits.

  9. Exception Handling:

    Ensure effective error management for governor limit exceptions by implementing error-handling mechanisms. This involves actively logging errors, delivering user-friendly messages, and taking appropriate actions when limits are reached.

  10. Regular Monitoring and Testing:

    Regularly monitor your Salesforce environment for resource usage. Implement testing procedures to identify potential bottlenecks and optimize code accordingly.

  11. Utilize Custom Indexes:

    In cases where queries are selective but still hit query row limits, consider utilizing custom indexes on fields to improve query performance.

  12. Consider Architectural Changes:

    Evaluate the overall architecture of your Salesforce solution. In some cases, architectural changes, such as data model optimizations, can have a significant impact on governor limit adherence.


By incorporating these strategies into your development practices, you can enhance the efficiency of your Salesforce applications and effectively work within the governor limits. In addition, staying informed about updates and new features from Salesforce may provide alternative solutions or optimizations to address specific limits.

Want To Learn More?

Learn about Execution Governors and Limits
Read more about Stop Struggling with Salesforce Layout Updates! Learn How to Disable Caching and Get Instant Results!

Share this article...

Salesforce Mentor, with 10 years Salesforce experience, Hardcore Admin & Guru Developer, Geek, Animal lover, and dog & cat rescuer activist. Lifetime student, Stand-Up comedian wannabe, Photographer, Gamer, Anime lover, and coffee addict. Spreading Salesforce love and teaching beyond my capacity. Aiming to become Tech Architect!

Leave a Reply

Your email address will not be published. Required fields are marked *