Blog Articles

chevron right

Salesforce

chevron right

Navigating the Salesforce Apex Governor Limits

blog image

Navigating the Salesforce Apex Governor Limits

Master Salesforce Apex Governor Limits for optimal development. Navigate constraints, boost performance, and create robust applications.

Navigating the Salesforce Apex Governor Limits
Himanshu Pant
Published: December 13, 2023

Key takeaways

  1. Salesforce Programmatic Tools: Salesforce's programmatic tools, including Apex, Visualforce, and Lightning Web Components, empower developers to create highly customized solutions, automate complex processes, and seamlessly integrate with external systems for enhanced CRM functionality.

  2. APIs for Seamless Integration: Salesforce's REST and SOAP APIs facilitate robust and versatile integration with external applications, ensuring smooth data exchange and creating a unified ecosystem that enhances the overall efficiency and interoperability of enterprise systems.

  3. Customization and Scalability: Salesforce's programmatic tools provide unparalleled customization and scalability, allowing developers to implement advanced business logic, create dynamic user interfaces, and optimize performance for growing organizations with unique and complex requirements.


Introduction

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:

CategoryLimitPurpose
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.

Conclusion

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.

Get a Fast Estimate on Your Software
Development Project

Related Posts

thumbnail
How Innostax Helped an Online Education Platform Modernize Its Entire Tech Stack

View Article
thumbnail
Streamlining Gladly Task Creation with Apex Code

In the realm of modern work dynamics, efficient task management is the linchpin of heightened…

View Article
thumbnail
Comprehensive Guide to Queueable Apex in Salesforce

Within the ever-evolving sphere of Salesforce development, where efficiency and scalability reign supreme, Queueable Apex…

View Article
thumbnail
Mastering Salesforce Data Governance: Best Practices Guide

In this guide, we will explore best practices for implementing Salesforce data governance. We will…

View Article
thumbnail
Comprehensive Guide to Batch Apex Classes in Salesforce

Introduction Within the dynamic landscape of Salesforce development, enhancing the processing of substantial datasets is…

View Article
thumbnail
A Deep Dive into Salesforce Automation Tools

Introduction Embarking on the ever evolving journey of contemporary business operations, Salesforce automation tools emerge…

View Article
© 2025 Innostax. All rights reserved. | Privacy
us-map

Web Development Services in the United States

  • Alabama
  • Alaska
  • Arizona
  • Arkansas
  • California
  • Colorado
  • Connecticut
  • Delaware
  • Florida
  • Georgia
  • Hawaii
  • Idaho
  • Illinois
  • Indiana
  • Iowa
  • Kansas
  • Kentucky
  • Louisiana
  • Maine
  • Maryland
  • Massachusetts
  • Michigan
  • Minnesota
  • Mississippi
  • Missouri
  • Montana
  • Nebraska
  • Nevada
  • New Hampshire
  • New Jersey
  • New Mexico
  • New York
  • North Carolina
  • North Dakota
  • Ohio
  • Oklahoma
  • Oregon
  • Pennsylvania
  • Rhode Island
  • South Carolina
  • South Dakota
  • Tennessee
  • Texas
  • Utah
  • Vermont
  • Virginia
  • Washington
  • West Virginia
  • Wisconsin
  • Wyoming