February 27, 2020

Governor Limits in Salesforce

Salesforce Governor Limits

Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources.

Why Salesforce has Governor Limits?

Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources.here salesforce online training If some Apex code exceeds a limit, the associated governor issues a runtime exception that cannot be handled.

Type 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

In this post we will mainly cover Per-Transaction Apex Limits.

These limits count for each Apex transaction. For Batch Apex, these limits are reset for each execution of a batch of records in the execute method.

This table lists limits for synchronous Apex and asynchronous Apex (Batch Apex and future methods) when they are different. Otherwise, this table lists only one limit that applies to both synchronous and asynchronous Apex. This table can be used as cheat sheet.

Here is list of important governor limits in salesforce

  • Total number of SOQL queries issued : 200
  • Total number of SOSL queries issued : 20
  • Total number of DML statements issued : 150
  • Total number of records retrieved by SOQL queries : 50,000
  • Total number of records processed as a result of DML statements : 10,000

Here is full list of governor limits in salesforce

For more details about governor limit, please refer to below link salesforce cpq training

Avoiding Governor limits

From a Developer’s perspective, it is important to ensure that our code should be scalable and should not hit the governor limits. Its very important to follow some of best practices so that our code does not hit governor limit. These are some of best practices that we should follow:

  • Bulkify your Code
  • Avoid SOQL Queries or DML statements inside FOR Loops
  • Bulkify your Helper Methods
  • Using Collections, Streamlining Queries, and Efficient For Loops
  • Streamlining Multiple Triggers on the Same Object
  • Querying Large Data Sets
  • Use of the Limits Apex Methods to Avoid Hitting Governor Limits
  • Use @future Appropriately
  • Use batch apex if you are working for more than 50000 records.
  • Never make any SOQL, DML operation inside the loop.

For more details, refer this APEX best Practices

For other Salesforce post, please refer this Salesforce online training in Hyderabad