Salesforce Governor Limits

Governor limits in Salesforce are used to ensure the effective use of resources on the Force.com multi-tenant platform. In order to execute the code efficiently, Salesforce.com sets some limits.

Before continuing, let’s take a look at what you will learn in this tutorial on Governor Limits in Salesforce:

What are Governor Limits in Salesforce?

To ensure that no one acquires resources from others, Force.com sets many restrictions that limit normal code execution. Salesforce has to do this because of its multi-tenant architecture, where all organizations and customers share a single resource. If one of the governor’s limits is not met, an error will be raised and the program will stop or halt. Therefore, it is important to ensure that our code is scalable and does not violate governor limits. These limits are called the single transaction basis, a single trigger execution.

Get 100% Hike!

Master Most in Demand Skills Now !

Types of Salesforce Governor Limits 

  • Per-transaction Certified Managed Package Limits
  • Static Apex Limits
  • Per-transaction Apex Limits
  • Lightning Platform Apex Limits
  • Size-specific Apex Limits

Interested in learning Salesforce? Enroll in our Salesforce Training now!

Lists of Governor Limits in Salesforce

Here are the lists of Governor Limits in Salesforce.

Major Governor Limits

Here is a Salesforce Governor Limits cheat sheet that overviews the essential limits that everyone should be aware of know:

Overview Governor Limit
The total number of SOSL queries issued in Salesforce 20
DML Governor Limits in Salesforce (Total number of statements issued per transaction) 150
Total number of records retrieved by a single SOSL query 2000
Total number of records retrieved by SOQL queries 50000
Total number of records retrieved by Database.getQueryLocator 10000
Salesforce Governor Limits for heap size total 6 MB/12 MB

Per-transaction Certified Managed Package Limits

Certified managed packages are managed packages that have passed AppExchange security checks for most transaction limits. Certified managed packages are developed by Salesforce ISV partners and installed in our org from AppExchange under a unique namespace.

With this governor limit, there is no limit to the number of certified namespaces that can be accessed through a single transaction. However, the prerequisite is that the number of operations that can be performed in a single namespace does not exceed the per-transaction limits. In addition, the total number of operations that can be performed in any transaction across the namespace is limited. The total limit for each namespace is 11 times. Shared limits on all namespaces are not affected by collective limits, such as a limit on maximum CPU time.

Description Cumulative Cross-namespace Limits
The total number of SOQL queries issued 1,100
The total number of records retrieved by Database.getQueryLocator 110,000
The total number of SOSL queries issued 220
The total number of DML statements issued 1,650
The total number of callouts (either HTTP requests or Web services calls) in a transaction 1,100
The total number of sendEmail methods allowed 110

Check our blog on Salesforce Database to get a complete understanding of its working in Salesforce.

All transaction limits count individually for certified managed packages expect:

  • Maximum CPU time
  • Total heap size
  • Maximum number of unique namespaces
  • Maximum transaction execution time

Each of these limits applies to all transactions, even as the number of certified managed packages running in the same transaction. If we install an AppExchange package created by an uncertified Salesforce ISV partner, the code for that particular package will not have its own governor limits. All resources used by the package are counted toward the total governor limit of the org. All collection resource messages and warning messages are also generated based on the corresponding package namespace.

Career Transition

Career Transition to Big Data - Yogesh's Success Story | Big Data Hadoop Course - Intellipaat Review
Intellipaat Reviews - Salesforce Training | Career Transition to Salesforce Marketing Cloud Admin
Salesforce Admin To Salesforce Developer | Got Job With Salary Hike | Intellipaat Career Transition
Intellipaat Reviews - Salesforce Training | Career Transition | Got a New Job With 100% Salary Hike
Got Job As a Salesforce Developer at Ericsson with Salary Hike | Intellipaat Career Transition
How to become a Salesforce Admin | Got Job Just After 1 Month | Intellipaat Career Transition

Want to learn about Salesforce Lightning? Check out our Salesforce Lightning tutorial.

Static Apex Limits

So far, we know that there are different governor limits for each description we give in Apex. There are more governor limits for Static Apex, i.e., for different kinds of callouts, queries, loops, records, and batch sizes, along with different transactions. Let’s look at these limits individually:

Description Limits
The default timeout of callouts (either HTTP requests or Web services calls) in a transaction 10 seconds
The maximum size of the callout request or response (either HTTP request or Web services call) 6 MB for synchronous Apex or 12 MB for asynchronous Apex
The maximum SOQL query runtime before Salesforce cancels the transaction 120 seconds
The maximum number of class and trigger code units in the deployment of Apex 5,000
Apex trigger batch size 200
For loop list batch size 200
The maximum number of records that are returned for a Batch Apex query in Database.QueryLocator 50 million

Learn about Order of Execution in Salesforce in our comprehensive blog now!

Per-transaction Apex Limits

Per-transaction Apex Limits are used for counting each Apex transaction. When we talk about Batch Apex, these specific limits in the execution method for executing each batch of records will be reset. The following table summarizes the limits for the synchronous and asynchronous Apex:

Description Synchronous Limits Asynchronous Limits
The total number of SOQL queries issued 100 200
The total number of records retrieved by SOQL queries 50,000
The total number of records retrieved by Database.getQueryLocator 10,000
The total number of SOSL queries issued 20
The total number of records retrieved by a single SOSL query 20,000
The total number of DML statements issued 150
The total number of records processed as a result of DML statements, Approval.process, or database.emptyRecycleBin 10,000
The total stack depth for any Apex invocation that recursively fires triggers with insert, update, or delete statements 16
The total number of callouts (either HTTP requests or Web services calls) in a transaction 100
The maximum cumulative timeout for all callouts (either HTTP requests or Web services calls) in a transaction 120 seconds
The maximum number of methods with the future annotation allowed per Apex invocation 50 0 in batch and future contexts and 1 in the queueable context
The maximum number of Apex jobs added to the queue with System.enqueueJob 50 1
The total number of sendEmail methods allowed 10
The total heap size 6MB 12MB
The maximum CPU time on Salesforce servers 10,000 milliseconds 60,000 milliseconds
The maximum execution time for each Apex transaction 10  minutes
The maximum number of push notification method calls allowed per Apex transaction 10
The maximum number of push notifications that can be sent through each push notification method call 2,000

 

Lightning Platform Apex Limits

The following limits do not apply to Apex transactions and are therefore managed by the Lightning platform.

Description Limit
The maximum number of asynchronous Apex method executions (Batch Apex, future methods, Queueable Apex, and Scheduled Apex) per 24-hour period Either 250,000 or the number of user licenses in the org multiplied by 200, whichever is greater
The number of synchronous concurrent transactions for long-running transactions, which last longer than 5 seconds for each org. 10
The maximum number of Apex classes scheduled concurrently 100. In Developer Edition org, the limit is 5
The maximum number of Batch Apex jobs in the Apex flex queue that is in the Holding status 100
The maximum number of Batch Apex jobs queued or active concurrently 5
The maximum number of Batch Apex job start method concurrent executions 1
The maximum number of batch jobs that can be submitted in a running test 5
The maximum number of test classes that can be queued in a 24-hour period (in Production org other than Developer Edition) Either 500 or 10 multiplied by the number of test classes in the org, whichever is greater
The maximum number of test classes that can be queued in a 24-hour period (Sandbox and Developer Edition org) Either 500 or 20 multiplied by the number of test classes in the org, whichever is greater
The maximum number of query cursors open concurrently per user 50
The maximum number of query cursors open concurrently per user for the Batch Apex start method 15
The maximum number of query cursors open concurrently per user for Batch Apex execute and finish methods 5

Preparing for a Salesforce Interview! Check out our Salesforce Admin Interview Questions.

Size-specific Apex Limits

Size-dependent Apex Limits are specifically designed to ensure that there are no oversized items in classes, triggers, org, etc.

The following table gives the limits for each of these:

Description Limit
The maximum number of characters in a class 1 million
The maximum number of characters in a trigger 1 million
The maximum amount of code used by all Apex codes in org1 6 MB
The method size limit 2 65,535 bytecode instructions in a compiled form

become a salesforce expert

Difference Between Synchronous and Asynchronous Execution

An Apex code can be run synchronously or asynchronously.

In synchronous execution, all of the code gets executed at once.

In asynchronous execution, a part of the process gets executed in the background after some time as a separate thread step. In such a scenario, users don’t need to wait for the process to finish. Asynchronous execution has bigger governor limits.

Advantages of Governor Limits in Salesforce

  • Governor limits in Salesforce prevent other org from using and hence executing lengthy code, which can take up a lot of space in the memory and even the entire cloud CPU.
  • Apex has completely different or unique coding limits.
  • These governor limits help us stay in the right space of coding with Apex.

Interested in learning Salesforce? Check out the Salesforce Training in Bangalore!

How can you avoid Salesforce Governor Limits?

As a developer, we need to ensure that our code is scalable and does not exceed the governor limits. But how? Follow this process to meet the governor limits in Salesforce:

  • Do not have DML statements or SOQL queries in our FOR loop
  • Try not to use SOQL or DML operations in the loop
  • Try to bulkify the code and helper methods
  • Query large data sets
  • Use Batch Apex if we want to process 50,000 records
  • Streamline various triggers on the same object
  • Use streamlining queries and collections for loops

I hope you now understand how the governor limits work in Apex and how to avoid them.

Prepare yourself for the industry by going through these Top Salesforce Interview Questions and Answers

Conclusion

We hope you now understand how the governor limits work in Apex and how to avoid them. When working on code and managing the organization, it is crucial to be aware of the limits that Salesforce has.

Visit our Salesforce Community to get answers to all your queries!

Course Schedule

Name Date Details
Salesforce Certification 23 Mar 2024(Sat-Sun) Weekend Batch
View Details
Salesforce Certification 30 Mar 2024(Sat-Sun) Weekend Batch
View Details
Salesforce Certification 06 Apr 2024(Sat-Sun) Weekend Batch
View Details