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 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.
  • getLimitAggregateQueries()
    Returns the total number of aggregate queries that can be processed with SOQL query statements.
  • getAsyncCalls()
    Reserved for future use.
  • getLimitAsyncCalls()
    Reserved for future use.
  • getCallouts()
    Returns the number of Web service statements that have been processed.
  • getChildRelationshipsDescribes()
    Deprecated. Returns the number of child relationship objects that have been returned.
  • getLimitCallouts()
    Returns the total number of Web service statements that can be processed.
  • getCpuTime()
    Returns the CPU time (in milliseconds) accumulated on the Salesforce servers in the current transaction.
  • getLimitCpuTime()
    Returns the time limit (in milliseconds) of CPU usage in the current transaction.
  • 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.
  • 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.
  • getDMLStatements()
    Returns the number of DML statements (such as insert, update or the database.EmptyRecycleBin method) that have been called.
  • getLimitDMLStatements()
    Returns the total number of DML statements or the database.EmptyRecycleBin methods that can be called.
  • getEmailInvocations()
    Returns the number of email invocations (such as sendEmail) that have been called.
  • getLimitEmailInvocations()
    Returns the total number of email invocation (such as sendEmail) that can be called.
  • getFindSimilarCalls()
    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.
  • getLimitFindSimilarCalls()
    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.
  • getFutureCalls()
    Returns the number of methods with the future annotation that have been executed (not necessarily completed).
  • getLimitFutureCalls()
    Returns the total number of methods with the future annotation that can be executed (not necessarily completed).
  • getHeapSize()
    Returns the approximate amount of memory (in bytes) that has been used for the heap.
  • getLimitHeapSize()
    Returns the total amount of memory (in bytes) that can be used for the heap.
  • getMobilePushApexCalls()
    Returns the number of Apex calls that have been used by mobile push notifications during the current metering interval.
  • getLimitMobilePushApexCalls()
    Returns the total number of Apex calls that are allowed per transaction for mobile push notifications.
  • getQueries()
    Returns the number of SOQL queries that have been issued.
  • getLimitQueries()
    Returns the total number of SOQL queries that can be issued.
  • getQueryLocatorRows()
    Returns the number of records that have been returned by the Database.getQueryLocator method.
  • getLimitQueryLocatorRows()
    Returns the total number of records that have been returned by the Database.getQueryLocator method.
  • getQueryRows()
    Returns the number of records that have been returned by issuing SOQL queries.
  • getLimitQueryRows()
    Returns the total number of records that can be returned by issuing SOQL queries.
  • getQueueableJobs()
    Returns the number of queueable jobs that have been added to the queue per transaction. A queueable job corresponds to a class that implements the Queueable interface.
  • getLimitQueueableJobs()
    Returns the maximum number of queueable jobs that can be added to the queue per transaction. A queueable job corresponds to a class that implements the Queueable interface.
  • getRunAs()
    Deprecated. Returns the same value as getDMLStatements.
  • getLimitRunAs()
    Deprecated. Returns the same value as getLimitDMLStatements.
  • getSavepointRollbacks()
    Deprecated. Returns the same value as getDMLStatements.
  • getLimitSavepointRollbacks()
    Deprecated. Returns the same value as getLimitDMLStatements.
  • getSavepoints()
    Deprecated. Returns the same value as getDMLStatements.
  • getLimitSavepoints()
    Deprecated. Returns the same value as getLimitDMLStatements.
  • getSoslQueries()
    Returns the number of SOSL queries that have been issued.
  • getLimitSoslQueries()
    Returns the total number of SOSL queries that can be issued.

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

getAsyncCalls()

Reserved for future use.

Signature

public static Integer getAsyncCalls()

Return Value

Type: Integer

getLimitAsyncCalls()

Reserved for future use.

Signature

public static Integer getLimitAsyncCalls()

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

getChildRelationshipsDescribes()

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

Signature

public static Integer getChildRelationshipsDescribes()

Return Value

Type: Integer

Usage

Note

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.

getLimitCallouts()

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

Signature

public static Integer getLimitCallouts()

Return Value

Type: Integer

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

getFindSimilarCalls()

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()

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 transaction 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

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

getQueueableJobs()

Returns the number of queueable jobs that have been added to the queue per transaction. A queueable job corresponds to a class that implements the Queueable interface.

Signature

public static Integer getQueueableJobs()

Return Value

Type: Integer

getLimitQueueableJobs()

Returns the maximum number of queueable jobs that can be added to the queue per transaction. A queueable job corresponds to a class that implements the Queueable interface.

Signature

public static Integer getLimitQueueableJobs()

Return Value

Type: Integer

getRunAs()

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()

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()

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()

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()

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()

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.

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