blog image
Blog Articles

Navigating the Salesforce Apex Governor Limits


Salesforce Apex, the powerful programming language for the Salesforce platform, enables developers to build robust and scalable applications. Salesforce imposes specific limits on Apex code execution known as “governor limits” to maintain a stable and reliable environment. These limits prevent poorly written or resource-intensive code from negatively impacting the performance of the Salesforce platform. In this blog post, we’ll explore the Salesforce Apex governor limits, understand their significance, and discuss strategies for optimizing code to ensure a smooth and efficient application.

Understanding Governor Limits

Governor limits in Salesforce are essentially a set of runtime constraints that restrict the amount of resources and data that a piece of Apex code can consume during execution. These limits exist to prevent monopolization of resources and to ensure that all organizations sharing the Salesforce infrastructure have a fair and predictable experience. Common governor limits include:

Governor LimitDescription
CPU Time LimitEvery Apex transaction is allocated a certain amount of CPU time.
SOQL and SOSL Query LimitsControl the number of records that can be queried in a single transaction.
DML Statement LimitsRestrictions on the number of records that can be inserted, updated, deleted, or undeleted.
Heap Size LimitRestricts the amount of memory (heap) available for Apex code execution.
Governor Limits on CalloutsLimits the number of callouts that can be made in a transaction to external services.

Optimizing Code for Governor Limits

To build efficient and scalable applications on the Salesforce platform, developers need to be mindful of governor limits. Here are some best practices for optimizing code:

Best PracticeDescription
Bulkify Your CodeDesign your code to handle bulk data processing rather than focusing on individual records.
Limit the Use of SOQL Queries in LoopsMinimize the number of SOQL queries inside loops to avoid hitting the query limit.
Use Asynchronous ProcessingConsider using asynchronous processing with features like Batch Apex or Queueable Apex.
Avoid Recursive TriggersImplement trigger controls to prevent recursion and avoid hitting CPU time limits.
Monitor and Analyze PerformanceRegularly monitor your application’s performance using Salesforce’s built-in tools.

Salesforce Governor Limits:

Salesforce imposes various governor limits to ensure the efficient use of resources and to prevent abuse that could negatively impact the performance of the platform. Below is a comprehensive list of Salesforce governor limits:

Apex CPU Time10,000 milliseconds per transaction (synchronous)Controls the total execution time for all Apex code in a transaction.
SOQL Queries100 SOQL queries per transactionRestricts the number of queries to the database to prevent inefficient data retrieval.
SOSL Queries20 SOSL queries per transactionGoverns the number of Salesforce Object Search Language queries to the search index.
DML Statements150 DML statements (insert, update, delete, merge) per transactionEnsures that transactions don’t manipulate excessive records in a single operation.
Total Heap Size6 MB for synchronous Apex, 12 MB for asynchronous ApexRestricts the amount of memory (heap) that Apex code can use during execution.
Email Invocations10 email messages sent per transaction
Controls the number of email messages that can be sent in a single transaction.
Future Method Invocations50 future method invocations per transactionGoverns the number of asynchronous (future) methods that can be queued in a transaction.
Queueable Jobs50 Queueable jobs added to the queue per transactionRestricts the number of jobs that can be added to the queue for asynchronous processing.
Batch Apex100 batch jobs queued or active concurrentlyGoverns the number of batch jobs that can be processed concurrently.
Streaming API Events20,000 events per 24-hour rolling windowControls the number of Streaming API events that can be published within a specified timeframe.
Platform Events2,000,000 published events per rolling 24-hour windowGoverns the number of platform events that can be published within a specified timeframe.
Callouts100 callouts per transaction (synchronous), 200 callouts per transaction (asynchronous)Restricts the number of HTTP callouts that can be made in a single transaction.
External Services5,000 external service callouts per 24 hoursGoverns the number of callouts to external services via External Services in a specified timeframe.
Dynamic Apex500,000 characters for the total size of Apex codeRestricts the size of dynamically generated Apex code.
Push Notifications2,000,000 push notifications per rolling 24-hour windowGoverns the number of push notifications that can be sent within a specified timeframe.


In conclusion, mastering the intricacies of Salesforce Apex Governor Limits is paramount for any developer aiming to create robust and efficient applications on the platform. As we’ve explored, these limits are in place to ensure the stability and performance of Salesforce environments, preventing resource abuse and optimizing overall system functionality. By understanding and navigating these limits judiciously, developers can strike a balance between innovation and adherence to best practices. Continuous monitoring, optimization, and leveraging Salesforce tools for performance analysis are essential components of successful development within the confines of Governor Limits. Ultimately, embracing these limits as guidelines rather than restrictions fosters the creation of scalable, reliable, and high-performing applications, enhancing the overall Salesforce development experience.

Sign Up Now
Get a Fast Estimate on Your Software Development Project

We are committed to delivering high-quality IT solutions tailored to meet the unique needs of our clients. As part of our commitment to transparency and excellence, we provide detailed project estimations to help our clients understand the scope, timeline, and budget associated with their IT initiatives.

Related Posts

Streamlining Gladly Task Creation with Apex Code

Introduction In the realm of modern work dynamics, efficient task management is the linchpin of heightened productivity. Gladly, an adept task management platform, opens new avenues for seamless task integration…

View Article
Comprehensive Guide to Queueable Apex in Salesforce

Introduction Within the ever-evolving sphere of Salesforce development, where efficiency and scalability reign supreme, Queueable Apex emerges as a dynamic and adaptable solution. This blog embarks on an in-depth exploration…

View Article
Mastering Salesforce Data Governance: Best Practices Guide

In this guide, we will explore best practices for implementing Salesforce data governance. We will examine the fundamental principles of data governance, setting up data governance in Salesforce, data modeling,…

View Article
Comprehensive Guide to Batch Apex Classes in Salesforce

Introduction Within the dynamic landscape of Salesforce development, enhancing the processing of substantial datasets is imperative for achieving peak efficiency and performance. This blog navigates the influential realm of Batch…

View Article
A Deep Dive into Salesforce Automation Tools

Introduction Embarking on the ever evolving journey of contemporary business operations, Salesforce automation tools emerge as catalysts, propelling organizations toward heightened efficiency, enhanced productivity, and elevated customer satisfaction. Within the…

View Article
Mastering Salesforce: The Power of Code for Custom Solutions

Introduction Salesforce, a trailblazer in cloud based CRM, provides developers with a robust set of programmatic tools for crafting bespoke solutions. In this blog, we'll explore the realm of Salesforce's…

View Article