Wednesday, June 28, 2017

Governor Limits in Salesforce:

Governor limits are runtime limits enforced by the Apex runtime engine. Because Apex runs in a shared, multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that code does not monopolize shared resources. Types of limits that Apex enforces are resources like memory, database resources, number of script statements to avoid infinite loops, and number of records being processed. If code exceeds a limit, the associated governor issues a runtime exception.

In Salesforce, it is the Governor Limits which controls how much data or how many records you can store in the shared databases. Why? Because Salesforce is based on the concept of multi-tenant architecture. In simpler words, Salesforce uses a single database to store the data of multiple clients/ customers. The below image will help you relate to this concept.

To make sure no single client monopolizes the shared resources, Salesforce introduced the concept of Governor Limits which is strictly enforced by the Apex run-time engine.
Governor Limits are a Salesforce developer’s biggest challenge. That is because if the Apex code ever exceeds the limit, the expected governor issues a run-time exception that cannot be handled. Hence as a Salesforce developer, you have to be very careful while developing your application.
Different Governor Limits in Salesforce are:


  • Per-Transaction Apex Limits
  • Force.com Platform Apex Limits
  • Static Apex Limits
  • Size-Specific Apex Limits
  • Miscellaneous Apex Limits
  • Email Limits
  • Push Notification Limits.
Salesforce Governor Limits


Since Apex runs in a multitenant environment, the Apex run time engine strictly enforces a number of limits to ensure that runaway Apex does not monopolize shared resources. These limits, or governors, track and enforce the statistics outlined in the following table. If some Apex code ever exceeds a limit, the associated governor issues a run time exception that cannot be handled.


Description
Limit
Total number of SOQL queries issued
100
Total number of SOQL queries issued for Batch Apex and future methods
200
Total number of records retrieved by SOQL queries
50,000
Total number of records retrieved by Database.getQueryLocator
10,000
Total number of SOSL queries issued
20
Total number of records retrieved by a single SOSL query
2000
Total number of DML statements issued
150
Total number of records processed as a result of DML statements,Approval.process, or database.emptyRecycleBin
10,000
Total number of executed code statements
200,000
Total number of executed code statements for Batch Apex and future methods
1,000,000
Total heap size
6 MB
Total heap size for Batch Apex and future methods
12 MB
Total stack depth for any Apex invocation that recursively fires triggers due toinsert, update, or delete statements
16
For loop list batch size
200
Total number of callouts (HTTP requests or Web services calls) in a request
10
Maximum timeout for all callouts (HTTP requests or Web services calls) in a request
120 seconds
Default timeout of callouts (HTTP requests or Web services calls) in a request
10 seconds
Total number of methods with the future annotation allowed per Apex invocation
50
Maximum size of callout request or response (HTTP request or Web services call)
3 MB
Total number of sendEmail methods allowed
10
Total number of describes allowed
100
Total number of classes that can be scheduled concurrently
25
Total number of test classes that can be queued per a 24–hour period
The greater of 500 or 10 multiplied by the number of test classes in the organization

Visualforce Limits

Available in: Contact Manager, Group, Professional, Enterprise,Performance, Unlimited, and Developer Editions


Limit

Value

Maximum response size for a Visualforce page

Less than 15 MB

Maximum view state size in a Visualforce page

135KB

Maximum size of a Visualforce email template

1 MB

Maximum file size for a file uploaded using a Visualforcepage

10 MB

Maximum size of HTML response before rendering, whenVisualforce page is rendered as PDF

Less than 15 MB

Maximum PDF file size for a Visualforce page rendered as a PDF

60 MB

Maximum total size of all images included in a Visualforcepage rendered as a PDF

30 MB

Maximum response size of a JavaScript remote call

15 MB

Default timeout for a JavaScript remoting call

30000milliseconds (30seconds)

Maximum timeout for a JavaScript remoting call

120000milliseconds (120seconds)

Maximum number of rows retrieved by queries for a singleVisualforce page request

50,000

Maximum number of rows retrieved by queries for a singleVisualforce page request in read-only mode

1 million

Maximum number of collection items that can be iterated in an iteration component such as <apex:pageBlockTable> and<apex:repeat>

1,000

Maximum number of collection items that can be iterated in an iteration component such as <apex:pageBlockTable> and<apex:repeat> in read-only mode

10,000

Maximum number of field sets that can be displayed on a single Visualforce page.

50

Maximum number of records that can be handled by StandardSetController

10,000



SOQL and SOSL Limits

Feature

Limit

Limit Description

SOQL statements

Maximum length of SOQL statements

By default, SOQL statements cannot exceed 20,000 characters in length.

SOSL statements

Maximum length of SOSL statements

The SOSL statement character limit is tied to the SOQL statement character limit defined for your organization. By default, SOQL and SOSL queries cannot exceed 20,000 characters.

SOSL search query strings

Maximum length ofSearchQuerystring

If the SearchQuery string is longer than 10,000 characters, no result rows are returned. If SearchQuery is longer than 4,000 characters, any logical operators are removed. For example, the ANDoperator in a statement with aSearchQuery that’s 4,001 characters will default to the OR operator, which could return more results than expected.

SOSL query results

Maximum number of rows returned

2,000 results total (API version 28.0 and later), unless you specify custom limits in the query. Previous API versions return 200 results.

Relationship queries

Relationship query limits

·         No more than 35 child-to-parent relationships can be specified in a query. A custom object allows up to 25 relationships, so you can reference all the child-to-parent relationships for a custom object in one query.
·         No more than 20 parent-to-child relationships can be specified in a query.
·         In each specified relationship, no more than five levels can be specified in a child-to-parent relationship. For example,Contact.Account.Owner.FirstName(three levels).
·         In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specifies Account, the SELECT clause can specify only the Contact or other objects at that level. It could not specify a child object of Contact.

 

FOR VIEW and FOR REFERENCE

MaximumRecentlyViewedrecords allowed

The RecentlyViewed object is updated every time the logged-in user views or references a record. It is also updated when records are retrieved using the FOR VIEW or FOR REFERENCE clause in a SOQL query. To ensure that the most recent data is available, RecentlyViewed data is periodically truncated down to 200 records per object.

OFFSET clause

Maximum number of rows skipped by OFFSET

·he maximum offset is 2,000 rows. Requesting an offset greater than 2,000 will result in aNUMBER_OUTSIDE_VALID_RANGE error.

ORDER BY clause in SOQL statement

ORDER BY fields limit

32 fields


Metadata Limits



The following are limits for deploying and retrieving metadata. These limits apply to the Force.com IDE, the Force.com Migration Tool, and the Metadata API.

Metadata Limit
                Limit Description
Retrieving and deploying metadata
Metadata API can deploy and retrieve up to 5,000 filesor 400 MB at one time.
While a specific file size limit is not enforced, you might encounter out-of-memory errors for very large files.

Change sets
Inbound and outbound change sets can have up to5,000 files of metadata.

Salesforce Custom objects and fields Limitation


Custom Objects and fields limitation is based on the Salesforce Edition (Group, Professional, Enterprise and Unlimited Editions)

Salesforce.com EditionsGroup EditionProfessional EditionEnterprise EditionUnlimited EditionDeveloper Edition
Total Custom Fields per Object100100500800500
Total Custom Objects50502002,000400


Per-Transaction Apex Limits:

Description
Synchronous Limit
Asynchronous Limit
Total number of SOQL queries issued1 (This limit doesn’t apply to custom metadata types. In a single Apex transaction, custom metadata records can have unlimited SOQL queries.)
100
200
Total number of records retrieved by SOQL queries
50,000
Total number of records retrieved by Database.getQueryLocator
10,000
Total number of SOSL queries issued
20
Total number of records retrieved by a single SOSL query
2,000
Total number of DML statements issued2
150
Total number of records processed as a result of DML statements, Approval.process, or database.emptyRecycleBin
10,000
Total stack depth for any Apex invocation that recursively fires triggers due to insert,update, or delete statements3
16
Total number of callouts (HTTP requests or Web services calls) in a transaction
100
Maximum cumulative timeout for all callouts (HTTP requests or Web services calls) in a transaction
120 seconds
Maximum number of methods with the future annotation allowed per Apex invocation
50
Maximum number of Apex jobs added to the queue with System.enqueueJob
50
Total number of sendEmail methods allowed
10
Total heap size4
6 MB
12 MB
Maximum CPU time on the Salesforce servers5
10,000 milliseconds
60,000 milliseconds
Maximum execution time for each Apex transaction
10 minutes
Maximum number of push notification method calls allowed per Apex transaction
10
Maximum number of push notifications that can be sent in each push notification method call
2,000

 

Per-Transaction Certified Managed Package Limits

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

Force.com Platform Apex Limits

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

Static Apex Limits

Description
Limit
Default timeout of callouts (HTTP requests or Web services calls) in a transaction

10 seconds
Maximum size of callout request or response (HTTP request or Web services call)1

6 MB for synchronous Apex or 12 MB for asynchronous Apex
Maximum SOQL query run time before Salesforce cancels the transaction
120 seconds
Maximum number of class and trigger code units in a deployment of Apex
5,000
For loop list batch size

200
Maximum number of records returned for a Batch Apex query in Database.QueryLocator
50 million

Size-Specific Apex Limits

Description
Limit
Maximum number of characters for a class
1 million
Maximum number of characters for a trigger
1 million
Maximum amount of code used by all Apex code in an org1

3 MB
Method size limit 2
65,535 bytecode instructions in compiled form

Email Limits:


When sending single emails, keep in mind:
·         You can specify up to 100 recipients for the To field and up to 25 recipients for the CC and BCC fields in eachSingleEmailMessage.
·         If you use SingleEmailMessage to email your org’s internal users, specifying the user’s ID in setTargetObjectId means the email doesn’t count toward the daily limit. However, specifying internal users’ email addresses in setToAddressesmeans the email does count toward the limit.
You can send mass email to a maximum of 5,000 external email addresses per day per org based on Greenwich Mean Time (GMT).

No comments:

Post a Comment