Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that runaway scripts do not monopolize shared resources. These limits, or governors, track and enforce the statistics outlined in the following table. If a script ever exceeds a limit, the associated governor issues a runtime exception that cannot be handled.
Governor limits are applied based on the entry point of your code. For example, if you have an anonymous block call a trigger, the limits that Apex runtime engine uses are the limits for the anonymous block, not for the trigger.
Governor limits apply to an entire organization, as well as to specific, certified namespaces. For example, if you install a certified managed package from Force.com AppExchange, (that is, an app that has been marked AppExchange Certified) the components in the package belong to a namespace unique from other components in your organization. Consequently, any Apex scripts in that package can issue up to 20 DML statements while executing. In addition, any Apex script that is native to your organization can also issue up to 20 DML statements, meaning more than 20 DML statements might execute during a single transaction if scripts from the certified managed package and your native organization both execute. Conversely, if you install a package from AppExchange that is not marked AppExchange Certified, the scripts from that package do not have their own separate governor limit count. Any resources they use count against the total for your organization. Cumulative resource messages and warning emails are also generated based on certified managed package namespaces as well. For more information on AppExchange Certified packages, see the Force.com AppExchange online help.
1 Test limits apply individually to each testMethod.
2 In a SOQL query with parent-child relationship sub-queries, each parent-child relationship counts as an additional query. These types of queries have a limit of three times the number for top-level queries. The row counts from these relationship queries contribute to the row counts of the overall script execution.
4 Trigger context is 10,000 statements plus 200 times the number of records in the top level call. For example, a DML statement that processes 200 records is subject to a limit of 10,000 + 200*200, which equals 50,000 statements. For a call with the future annotation, the limit is 10,000 statements.
5 Recursive Apex that does not fire any triggers with insert, update, or delete statements exists in a single invocation, with a single stack. Conversely, recursive Apex that fires a trigger spawns the trigger in a new Apex invocation, separate from the invocation of the code that caused it to fire. Because spawning a new invocation of Apex is a more expensive operation than a recursive call in a single invocation, there are tighter restrictions on the stack depth of these types of recursive calls.
6 These limits scale with trigger batch size. The limit is multiplied by the number of records submitted. For example, if your batch process contains 200 records, your script may retrieve as many as 200,000 records.
7 Salesforce.com also imposes an organization-wide limit of 200 method calls with the future annotation per license per 24 hours.
8 These limits are set to 0 for Visualforce controllers associated with custom components because those controllers cannot execute SOQL, SOSL, or DML statements. For more information, see “Custom Component Controllers” in the Visualforce Developer's Guide.
Use the Limits methods to determine the script execution limits for your code while it is running. For example, you can use the getDMLStatements method to determine the number of DML statements that have already been called by your program, or the getLimitDMLStatements method to determine the total number of DML statements available to your code in that context.
For more information, see “Limits Methods” in the Apex Code Developer's Guide.
In addition to the execution governor limits, Apex has the following limits: