Limits Class

Contains methods that return limit information for specific resources.

Namespace

System

Usage

The Limits methods return the specific limit for the particular governor, such as the number of calls of a method or the amount of heap size remaining.

Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that runaway Apex doesn’t monopolize shared resources.

None of the Limits methods require an argument. The format of the limits methods is as follows:

myDMLLimit = Limits.getDMLStatements();

There are two versions of every method: the first returns the amount of the resource that has been used while the second version contains the word limit and returns the total amount of the resource that is available.

See Understanding Execution Governors and Limits.

Limits Methods

The following are methods for Limits. All methods are static.

getAggregateQueries()

Returns the number of aggregate queries that have been processed with any SOQL query statement.

Signature

public static Integer getAggregateQueries()

Return Value

Type: Integer

getLimitAggregateQueries()

Returns the total number of aggregate queries that can be processed with SOQL query statements.

Signature

public static Integer getLimitAggregateQueries()

Return Value

Type: Integer

getCallouts()

Returns the number of Web service statements that have been processed.

Signature

public static Integer getCallouts()

Return Value

Type: Integer

getLimitCallouts()

Returns the total number of Web service statements that can be processed.

Signature

public static Integer getLimitCallouts()

Return Value

Type: Integer

getChildRelationshipsDescribes()

Deprecated. Returns the number of child relationship objects that have been returned.

Signature

public static Integer getChildRelationshipsDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getLimitChildRelationshipsDescribes()

Deprecated. Returns the maximum number of child relationship objects that can be returned.

Signature

public static Integer getLimitChildRelationshipsDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getCpuTime()

Returns the CPU time (in milliseconds) accumulated on the Salesforce servers in the current transaction.

Signature

public static Integer getCpuTime()

Return Value

Type: Integer

getLimitCpuTime()

Returns the time limit (in milliseconds) of CPU usage in the current transaction.

Signature

public static Integer getLimitCpuTime()

Return Value

Type: Integer

getDMLRows()

Returns the number of records that have been processed with any statement that counts against DML limits, such as DML statements, the Database.emptyRecycleBin method, and other methods.

Signature

public static Integer getDMLRows()

Return Value

Type: Integer

getLimitDMLRows()

Returns the total number of records that can be processed with any statement that counts against DML limits, such as DML statements, the database.EmptyRecycleBin method, and other methods.

Signature

public static Integer getLimitDMLRows()

Return Value

Type: Integer

getDMLStatements()

Returns the number of DML statements (such as insert, update or the database.EmptyRecycleBin method) that have been called.

Signature

public static Integer getDMLStatements()

Return Value

Type: Integer

getLimitDMLStatements()

Returns the total number of DML statements or the database.EmptyRecycleBin methods that can be called.

Signature

public static Integer getLimitDMLStatements()

Return Value

Type: Integer

getEmailInvocations()

Returns the number of email invocations (such as sendEmail) that have been called.

Signature

public static Integer getEmailInvocations()

Return Value

Type: Integer

getLimitEmailInvocations()

Returns the total number of email invocation (such as sendEmail) that can be called.

Signature

public static Integer getLimitEmailInvocations()

Return Value

Type: Integer

getFieldsDescribes()

Deprecated. Returns the number of field describe calls that have been made.

Signature

public static Integer getFieldsDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getLimitFieldsDescribes()

Deprecated. Returns the maximum number of field describe calls that can be made.

Signature

public static Integer getLimitFieldsDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getFieldSetsDescribes()

Deprecated. Returns the number of field set describe calls that have been made.

Signature

public static Integer getFieldSetsDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getLimitFieldSetsDescribes()

Deprecated. Returns the maximum number of field set describe calls that can be made.

Signature

public static Integer getLimitFieldSetsDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getFindSimilarCalls()

This method is deprecated. Returns the same value as getSoslQueries. The number of findSimilar methods is no longer a separate limit, but is tracked as the number of SOSL queries issued.

Signature

public static Integer getFindSimilarCalls()

Return Value

Type: Integer

getLimitFindSimilarCalls()

This method is deprecated. Returns the same value as getLimitSoslQueries. The number of findSimilar methods is no longer a separate limit, but is tracked as the number of SOSL queries issued.

Signature

public static Integer getLimitFindSimilarCalls()

Return Value

Type: Integer

getFutureCalls()

Returns the number of methods with the future annotation that have been executed (not necessarily completed).

Signature

public static Integer getFutureCalls()

Return Value

Type: Integer

getLimitFutureCalls()

Returns the total number of methods with the future annotation that can be executed (not necessarily completed).

Signature

public static Integer getLimitFutureCalls()

Return Value

Type: Integer

getHeapSize()

Returns the approximate amount of memory (in bytes) that has been used for the heap.

Signature

public static Integer getHeapSize()

Return Value

Type: Integer

getLimitHeapSize()

Returns the total amount of memory (in bytes) that can be used for the heap.

Signature

public static Integer getLimitHeapSize()

Return Value

Type: Integer

getMobilePushApexCalls()

Returns the number of Apex calls that have been used by mobile push notifications during the current metering interval.

Signature

public static Integer getMobilePushApexCalls()

Return Value

Type:Integer

getLimitMobilePushApexCalls()

Returns the total number of Apex calls that are allowed per day for mobile push notifications.

Signature

public static Integer getLimitMobilePushApexCalls()

Return Value

Type:Integer

getQueries()

Returns the number of SOQL queries that have been issued.

Signature

public static Integer getQueries()

Return Value

Type: Integer

getLimitQueries()

Returns the total number of SOQL queries that can be issued.

Signature

public static Integer getLimitQueries()

Return Value

Type: Integer

getPicklistDescribes()

Deprecated. Returns the number of PicklistEntry objects that have been returned.

Signature

public static Integer getPicklistDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getLimitPicklistDescribes()

Deprecated. Returns the maximum number of PicklistEntry objects that can be returned.

Signature

public static Integer getLimitPicklistDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getQueryLocatorRows()

Returns the number of records that have been returned by the Database.getQueryLocator method.

Signature

public static Integer getQueryLocatorRows()

Return Value

Type: Integer

getLimitQueryLocatorRows()

Returns the total number of records that have been returned by the Database.getQueryLocator method.

Signature

public static Integer getLimitQueryLocatorRows()

Return Value

Type: Integer

getQueryRows()

Returns the number of records that have been returned by issuing SOQL queries.

Signature

public static Integer getQueryRows()

Return Value

Type: Integer

getLimitQueryRows()

Returns the total number of records that can be returned by issuing SOQL queries.

Signature

public static Integer getLimitQueryRows()

Return Value

Type: Integer

getRecordTypesDescribes()

Deprecated. Returns the number of RecordTypeInfo objects that have been returned.

Signature

public static Integer getRecordTypesDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getLimitRecordTypesDescribes()

Deprecated. Returns the maximum number of RecordTypeInfo objects that can be returned.

Signature

public static Integer getLimitRecordTypesDescribes()

Return Value

Type: Integer

Usage

Note
Because describe limits are no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is available but is deprecated.

getRunAs()

This method is deprecated. Returns the same value as getDMLStatements.

Signature

public static Integer getRunAs()

Return Value

Type: Integer

Usage

The number of RunAs methods is no longer a separate limit, but is tracked as the number of DML statements issued.

getLimitRunAs()

This method is deprecated. Returns the same value as getLimitDMLStatements.

Signature

public static Integer getLimitRunAs()

Return Value

Type: Integer

Usage

The number of RunAs methods is no longer a separate limit, but is tracked as the number of DML statements issued.

getSavepointRollbacks()

This method is deprecated. Returns the same value as getDMLStatements.

Signature

public static Integer getSavepointRollbacks()

Return Value

Type: Integer

Usage

The number of Rollback methods is no longer a separate limit, but is tracked as the number of DML statements issued.

getLimitSavepointRollbacks()

This method is deprecated. Returns the same value as getLimitDMLStatements.

Signature

public static Integer getLimitSavepointRollbacks()

Return Value

Type: Integer

Usage

The number of Rollback methods is no longer a separate limit, but is tracked as the number of DML statements issued.

getSavepoints()

This method is deprecated. Returns the same value as getDMLStatements.

Signature

public static Integer getSavepoints()

Return Value

Type: Integer

Usage

The number of setSavepoint methods is no longer a separate limit, but is tracked as the number of DML statements issued.

getLimitSavepoints()

This method is deprecated. Returns the same value as getLimitDMLStatements.

Signature

public static Integer getLimitSavepoints()

Return Value

Type: Integer

Usage

The number of setSavepoint methods is no longer a separate limit, but is tracked as the number of DML statements issued.

getScriptStatements()

Deprecated. Returns a value that is based on CPU time usage and that is an approximation of script statement usage.

Signature

public static Integer getScriptStatements()

Return Value

Type: Integer

Usage

Note
Because the script statement limit is no longer enforced in any API version, this method is no longer available. Call getCpuTime() instead. In API version 30.0 and earlier, this method is still available but is deprecated and returns only an approximation of statement usage. The formula that is used to compute the return value is based on the ratio of CPU time that is used toward your transaction’s CPU timeout limit.

getLimitScriptStatements()

Deprecated. Returns the maximum number of Apex statements that can execute.

Signature

public static Integer getLimitScriptStatements()

Return Value

Type: Integer

Usage

Note
Because the script statement limit is no longer enforced in any API version, this method is no longer available. In API version 30.0 and earlier, this method is still available but is deprecated. Call getLimitCpuTime() instead.

getSoslQueries()

Returns the number of SOSL queries that have been issued.

Signature

public static Integer getSoslQueries()

Return Value

Type: Integer

getLimitSoslQueries()

Returns the total number of SOSL queries that can be issued.

Signature

public static Integer getLimitSoslQueries()

Return Value

Type: Integer

© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.