top of page
Search
Writer's pictureDeepak

All you need to know about Salesforce Governor limits

Updated: Jul 10, 2020

Have you ever come across errors such as LimitException:Too manySOQLqueries:101, CPU time limit exceed, Too many Query rows: 50001 etc. and wondered what are these? These are Salesforce governor limits, we also call it apex governor limits. Is there any other Governor Limits in Salesforce?


What is Salesforce Governor limits?


Salesforce governor limits are limit put up by Salesforce engine to protect its multitenant nature. As you know Salesforce engine runs in multitenant environment which makes sure that all the tenets get equal share of resources without any challenges. Apex runtime engine strictly enforces Salesforce Governor Limits so that runaway apex code or processes don’t monopolize shared resources.


Types of Salesforce Governor limits.

  • Per-Transaction Apex Limits

  • Per-Transaction Certified Managed Packaged Limits

  • Lightning Apex Limits

  • Static Apex Limits

  • Size specific Apex Limits

  • Miscellaneous Apex Limits


Per-Transaction Apex Limits


Salesforce run time engine keeps an eye on all the apex resource used during a transaction and throws an error if it crosses any of such limits.

These limits apply to all apex transaction. In case of batch apex these limits are reset for each execution of a batch of records in the execute method.




Per-Transaction Certified Managed Package Limits


Managed packages are apps typically used by Salesforce Partners to distribute and sell applications to customers. These packages must be created from a Developer Edition organization. Using the AppExchange and the License Management Application (LMA), developers can sell and manage user-based licenses to the app.


These apps have their own Salesforce Governor Limits on their namespace.


  1. If you install a certified managed package, all the Apex code in that package gets its own 150 DML statements. These DML statements are in addition to the 150 DML statements your org’s native code can execute, same is applicable for SOQL query, you get 100 for managed package and 100 for your own org and so on and so forth.

  2. There’s no limit on the number of certified namespaces that can be invoked in a single transaction. However, the number of operations that can be performed in each namespace must not exceed the per-transaction salesforce governor limits.

  3. These cumulative transactions can not exceed 11 times the actual limit. if the per-namespace limit for SOQL queries is 100, a single transaction can perform up to 1,100 SOQL queries with all managed apps together.


Cumulative Salesforce governor limit per transactions are as such:



Note: All per-transaction limits count separately for certified managed packages except for The total heap size, The maximum CPU time, The maximum transaction execution time, The maximum number of unique namespaces.



Lightning Platform Apex Limits


Lightning Platform enforces these limits such as




Static Apex Limit



Note: The HTTP request and response sizes count towards the total heap size. Also, Apex trigger batch size for platform events and Change Data Capture events is 2,000.



Size-Specific Apex limits




Miscellaneous Apex limit


  1. The maximum number of records that an event report returns for a user who is not a system administrator is 20,000; for system administrators, 100,000

  2. The maximum number of rows that can be inserted, updated, or deleted, in a single, synchronous Apex test execution context, is limited to 450,000. For example, an Apex class can have 45 methods that insert 10,000 rows each. If the limit is reached, you see this error:Your runallTestsisconsuming too many DB resources

  3. Developers receive an error message when a non-selective query in a trigger executes against an object that contains more than 200,000 records. To avoid this error, ensure that the query is selective.

  4. For classes in theConnectApinamespace, every write operation costs one DML statement against the Apex governor limit.

  5. Push Notification: an org can send up to 20,000 iOS and 10,000 Android push notifications per hour (for example, 4:00 to 4:59 UTC).

  6. Email Services: Maximum Size of Email Message cannot be more than 25MB.

  7. Email Services: Maximum number of email messages processed will be number of user licenses multiplied by 1,000; maximum 1,000,000



Here is some commonly asked questions related to Salesforce Governor Limits in any Salesforce interviews.

  • How to overcome SOQL error: Too manySOQLqueries:101, which occur due to Salesforce Governor Limits?

There are few things which you must do to avoid these errors such as, don’t write SOQL query in

a for loop(most common mistake), if you querying same object in a single transaction then make sure you find a common where clause and query the object once, filter out as and when needed

and use it. These two will drastically reduce your SOQL counts. If your query limits still going

beyond 100, try to break the transaction by using future methods if possible.

  • How to fix mixed DML error? Does it occur due to Salesforce Governor Limits?

When you try DML operation on Setup Objects and non Setup objects in a single transaction,

mixed DML error will occur. This is mainly due to conflict of interest between these 2 objects.

For example if you try to update user and opportunity object in a same

transaction then a conflict will arrive due to user access to opportunity. Which will force to stop

the transaction.This restriction exists because some sObjects affect the user’s access to records

in the org. You must insert or update these types of sObjects in a different transaction to revent

operations from happening with incorrect access-level permissions. For example, you can’t

update an Opportunity and User role in a single transaction.

  • Why do we get Heap Size error? Is it related to Salesforce Governor Limits?

The "Apex heap size too large" error occurs when too much data is being stored in memory during

processing. Here are some best practices for Heap Size.

-> Don't use class level variables to store a large amount of data.

-> Utilize SOQL For Loops to iterate and process data from large queries.

-> Construct methods and loops that allow variables to go out of scope as soon as they are no

longer needed.

-> Keep in mind that Salesforce enforces an Apex Heap Size Limit of 6MB for synchronous

transactions and 12MB for asynchronous transactions.

  • Can DML Salesforce Governor limit of 150 per transaction create problem? How can be over come DML limit issue?

Yes, Salesforce Governor limit of 150 DML per transaction will enforce you not to go beyond

this. The best way to avoid these errors is by bulkifying your code. Make sure you don’t put any

DML into a for loop.


Reference : Salesforce official blogs.

518 views0 comments

Recent Posts

See All

Comments


bottom of page