governor limits salesforce

Governor Limits Salesforce

Last updated on 10th Oct 2020, Blog, Tutorials

About author

Kathir ((Associate Director - Salesforce ) )

He is A TOP Rated Domain Expert with 7+ Years Of Experience Also, He is a Technology Writer for Past 5 Years to Imparts Informative Blog for Fresher's & JOB Seeker

(5.0) | 12547 Ratings 2064

Salesforce governor Limits are a concept that exists because Salesforce and Apex run in a multitenant environment. Multitenancy is a fundamental technology that sits alongside cloud computing.

Back when on-premise servers ruled the earth, you would purchase one or many servers to sit within your office or home. These servers would run your applications, and you would own the full processing power and storage capacity. You would also be responsible for the upkeep, maintenance, and upgrades. Fast forward to today, multitenancy allows us to share resources with other users of an application, in a cost-effective and secure manner.

In this article, we explain what Governor Limits in Salesforce actually are, some examples of the different types and also why they are so important within a multitenancy set-up.

Subscribe For Free Demo

Error: Contact form not found.

What is Salesforce Multitenancy?

Salesforce-Multitanancy

Salesforce operates on a form of software multitenancy. In layman’s terms, this means that a single instance of a software (in this case Salesforce), runs on a server that is able to serve multiple users.

Due to the nature of multitenancy and the fact we are sharing resources, governor limits are in place to ensure that any Apex we develop, does not monopolize the shared resources we are allocated.

Imagine this: there are 100 flats in a single apartment building. The 100 flats share resources: water, electricity, gas and wi-fi bandwidth. Imagine if several flats started some bitcoin mining which started to hog all of the electricity. Then imagine if some other flats started to download huge 4k video files from the interwebs. And then also imagine if some other flats were running baths all at the same time. If you lived in this apartment building, things would turn into a nightmare. You wouldn’t be able to stream any videos online in any reasonable time frame, your electricity bills would quadruple in a single month and the water pressure in your shower would decline to an embarrassing trickle.

The apartment building is a Salesforce instance (also known as a pod or server). The flats are the individual Salesforce orgs (there can be tens of thousands of orgs on a single sever). The distribution of shared resources is the multi-tenancy architecture.

This analogy helps to explain why governor limits are so helpful – they prevent inconsiderate actors from hogging database, memory, network or processor resources that you and other customers on the same server need to effectively run their business processes in the cloud. So, governor limits dictate what your code can and cannot do when it is executed on the Salesforce platform. And this contributes to the scalability of the platform since the resource allocation is defined.

What are Salesforce Governor Limits?

Simply put, Salesforce Governor Limits are usage caps enforced by Salesforce to ensure efficient processing. They allow for multiple users of the platform without impeding performance.

There are many different types of governor limits, some of which are tied to your Salesforce edition. For example, Professional Edition enables one to have 50 custom objects but 2,000 for Unlimited and Performance.

Some other governor limits have ‘soft’ limits that can either be solved by Salesforce or by purchasing additional add-ons. For example, the current limit is 6MB of Apex code per org but this can be increased on a case by case basis by Salesforce Support. Other limits are based on a combination of both your Salesforce edition but also the number of user licenses on the org. For example, API and data storage limits.

Other governor limits are associated more with programming in Apex: for example, an Apex class / execute anon script can only have 100 SELECT statements per synchronous transaction. Some of these limits are ‘hard’, meaning that they cannot be increased and so a new approach by the developer would be needed to achieve the desired result.

IMPORTANT GOVERNOR LIMITS IN SALESFORCE

  • One transaction can use a maximum of 100 Salesforce Object Query Language (SOQL) Queries.
  • A maximum of 20 SOSL requests can be used in one transaction.
    One transaction can use a maximum of 150 Data Manipulation Language (DML) statements.
  • In one transaction, a maximum of 50,000 SOQL records can be retrieved.
  • In one transaction, a maximum of 2,000 SOSL entries can be fetched.

TYPES OF GOVERNOR LIMITS:

  • Per-Transaction Apex Limits
  • Per-Transaction Certified Managed Package Limits
  • Lightning Platform Apex Limits
  • Static Apex Limits
  • Size-Specific Apex Limits
  • Miscellaneous Apex Limit

WHAT ARE THE IDEAL WAYS TO AVOID SALESFORCE GOVERNOR LIMITS?

From a developer’s perspective, it’s important to ensure that your code is scalable and doesn’t reach the governor limits. It is very important to follow some best practices so that your Code does not reach the governor’s limit.

Here are some best practices that you should follow:

  • Avoid SOQL Queries or DML statements inside FOR loops.
  • Use collections, optimize queries, and efficient FOR loops.
  • Optimizes multiple triggers on the same object.
  • Use the Peak Limitation Method to Avoid Limiting the Governor’s Population.
  • Use @Future annotation to bypass the Governor limit errors.
  • Use Batch Apex if you are working with more than 50,000 records.
  • Decrease the count of queries and try to fetch all needed data in the same query than calling again and again to Database.

Custom Field Salesforce Governor Limits Cheat sheet:

The custom field also has some governor limits. A Custom field allowed per object varies according to your Salesforce Edition. Let us see custom fields salesforce governor limits cheat sheet in detail below.

Field

Type

Personal Edition Contact Manager Group Edition professional Edition Enterprise Edition Developer Edition

Unlimited

&

Performance Edition

Activities No additional limit No additional limit No additional limit 20   100 100 100
Roll-up summary No additional limit 25 25 25 25 25 25
Relationship No additional limit 40 40 40 40 40 40
Course Curriculum

Get Practical Oriented Salesforce Training to UPGRADE Your Skill Set

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

Salesforce Governor Limits Cheat Sheet

Below are some important Salesforce.com governor limits that you should know when planning to enter the Salesforce field or working on some Salesforce project.

Description Governor Limit
Total number of SOSL queries issued in Salesforce 20
Total number of DML statements issued 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
Total heap size 6 MB/12 MB

Note: You could check other governor limits in Salesforce using Salesdorce.com governor limits guide. Also, you may download the salesforce governor limits pdf for your reference. The salesforce governor limits pdf contains all governor limits and how they can be used in Salesforce.

How to overcome Salesforce governor limits:

You can’t overcome Salesforce governor limits but you can do things in a proper way to avoid this. Salesforce has different limits for different things. Like in apex you can’t use more than 100 SOQL queries, can’t use more than 150 DML operations, etc. Please take care of these things while coding:

  1. 1. Try to use fewer script statements.
  2. 2. Use batch apex if you are working for more than 50000 records.
  3. 3. Never make any SOQL, DML operation inside the loop.
  4. 4. Use @future whenever needed.

Most importantly, you may prefer an asynchronous apex to overcome governor limits in Salesforce.

Salesforce Email Governor Limits

We can send notifications to users every time they invoke the Apex code. Let us have a quick look at steps to set up Salesforce email governor limits.

  • Go to Setup | Administer | Manage users | Users | Edit
  • From the given settings, select the checkbox to send warning emails through the administrator profile. 
  • If this feature is not activated then you may send apex warning emails in Salesforce.

Different kinds of Governor limits

1. Per-transaction certified managed Package Limits.

These managed packages are those who have passed AppExchange security checks for majority transaction limits. These managed packages are designed by salesforce ISV Partners and set up in our organization through AppExchange within a single namespace.

We can access any amount of certified namespaces with the help of a single transaction. Though, the precondition is that the number of operations which can be carried out in a separate namespace which should not surpass the per-transaction limits.

Moreover, the operations which can be carried out in the transaction throughout the namespace is restricted. For each namespace the overall limit is 11times. 

Every transaction limits count separately for certified managed packets anticipate

  • Effective CPU utilization.
  • Complete heap size
  • Numerous unique namespaces
  • Best transaction implementation time.

All the restrictions mentioned above apply to all transactions, still if the amount of certified managed packages working in the same transaction. When we set up an AppExchange package generated by an unauthorized Salesforce ISV partner, the code part of that specific package won’t have its governor limits.

2. Static Apex Limits

Till now, we are aware of various governor limits corresponding to every description given in apex. We observe additional governor limits i.e. for various types of callouts, loops, queries and records together with multiple transactions.

DescriptionLimits
The callouts default timeout for every transaction10 seconds
callout request or response maximum size6 to 12 MegaBytes.
Maximum SOQL runtime prior salesforce abolishes transaction2 Minutes
The maximum amount of trigger code units and classes in the apex implementation5,000
Batch size of apex trigger200
Batch size of For loop list200
Number of records reverted for a batch apex query within Database.queryLocator50 million

3. Per transaction apex limits

These limits are useful for counting every apex transaction. While we discuss batch apex, limits which are present for executing records batch are reactivated.  

DescriptionSynchronous limitsAsynchronous limits
Total SOQL Queries used100200
SOQL Queries retrieved records50,000 
Issued SOSL Queries20 
Issued DML Statements150 
The total amount of callouts per transaction100 
Allowed send email Methods10 
Apex transaction execution time10 minutes 
  Salesforce Servers CPU time10,00060,000 

4. Lightning Platform apex limits

The below-mentioned limits are not applicable for apex transactions, so lightning platform handles these limits.

DescriptionLimit
The maximum amount of asynchronous method executions in 24 hours25,000 
Parallelly scheduled apex classes100. 
Queued apex jobs or active parallelly5
The maximum amount of batches submitted5
Parallelly opened query cursors  per user 50
Parallelly opened query cursors  per user 15
Salesforce Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

5. Size-specific Apex Limits

Depending on the size these limits are particularly designed to assure that no outsized items are present in the classes.

Following table provides the limits of size-specific apex limits

DescriptionLimit
The maximum amount of characters per class1 mn
The maximum amount of triggers per class1 million
Apex maximum code utilization6MB
Limit 2 of methode size65,535 

Benefits of Governor limits

Apex has entirely different or individual coding limits.

Governor limits assist us to stay within the appropriate place of apex coding.

How to avoid Governor Limits

We can avoid governor limits by the following process

  • Avoid DML Statements and SOQL queries within the For Loop
  • Make sure that apex code manages more than one record at a time.
  • For loops, we should use collections.
  • Streamline different triggers over the same page.

In conclusion, there are many different types of governor limits across Salesforce and for good reason – to help us become more efficient developers and admins. There are some general patterns that you can adopt to ensure that you stay below the limits. Generally speaking, the most well-known limits are those around SOQL and DML limits in a single transaction. You also learned that getting past governor limits can be challenging and fun at the same time.

Are you looking training with Right Jobs?

Contact Us

Popular Courses