Limits Methods

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

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.

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.

Name Return Type Description
getAggregateQueries Integer Returns the number of aggregate queries that have been processed with any SOQL query statement.
getLimitAggregateQueries Integer Returns the total number of aggregate queries that can be processed with SOQL query statements.
getCallouts Integer Returns the number of Web service statements that have been processed.
getLimitCallouts Integer Returns the total number of Web service statements that can be processed.
getChildRelationshipsDescribes Integer Returns the number of child relationship objects that have been returned.
getLimitChildRelationshipsDescribes Integer Returns the total number of child relationship objects that can be returned.
getCpuTime Integer 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.

Returns -1 if called in a context where there is no CPU time limit such as in a test method.

getDMLRows Integer 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 Integer 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 Integer Returns the number of DML statements (such as insert, update or the database.EmptyRecycleBin method) that have been called.
getLimitDMLStatements Integer Returns the total number of DML statements or the database.EmptyRecycleBin methods that can be called.
getEmailInvocations Integer Returns the number of email invocations (such as sendEmail) that have been called.
getLimitEmailInvocations Integer Returns the total number of email invocation (such as sendEmail) that can be called.
getFieldsDescribes Integer Returns the number of field describe calls that have been made.
getLimitFieldsDescribes Integer Returns the total number of field describe calls that can be made.
getFieldSetsDescribes Integer Returns the number of field set describe calls that have been made.
getLimitFieldSetsDescribes Integer Returns the total number of field set describe calls that can be made.
getFindSimilarCalls Integer 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.
getLimitFindSimilarCalls Integer 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.
getFutureCalls Integer Returns the number of methods with the future annotation that have been executed (not necessarily completed).
getLimitFutureCalls Integer Returns the total number of methods with the future annotation that can be executed (not necessarily completed).
getHeapSize Integer Returns the approximate amount of memory (in bytes) that has been used for the heap.
getLimitHeapSize Integer Returns the total amount of memory (in bytes) that can be used for the heap.
getInteractionQueries Integer Returns the total number of interactions performed.
getLimitInteractionQueries Integer Returns the total number of interactions that can occur.
getQueries Integer Returns the number of SOQL queries that have been issued.
getLimitQueries Integer Returns the total number of SOQL queries that can be issued.
getPicklistDescribes Integer Returns the number of PicklistEntry objects that have been returned.
getLimitPicklistDescribes Integer Returns the total number of PicklistEntry objects that can be returned.
getQueryLocatorRows Integer Returns the number of records that have been returned by the Database.getQueryLocator method.
getLimitQueryLocatorRows Integer Returns the total number of records that have been returned by the Database.getQueryLocator method.
getQueryRows Integer Returns the number of records that have been returned by issuing SOQL queries.
getLimitQueryRows Integer Returns the total number of records that can be returned by issuing SOQL queries.
getRecordTypesDescribes Integer Returns the number of RecordTypeInfo objects that have been returned.
getLimitRecordTypesDescribes Integer Returns the total number of RecordTypeInfo objects that can be returned.
getRunAs Integer This method is deprecated. Returns the same value as getDMLStatements. The number of RunAs methods is no longer a separate limit, but is tracked as the number of DML statements issued.
getLimitRunAs Integer This method is deprecated. Returns the same value as getLimitDMLStatements. The number of RunAs methods is no longer a separate limit, but is tracked as the number of DML statements issued.
getSavepointRollbacks Integer This method is deprecated. Returns the same value as getDMLStatements. The number of Rollback methods is no longer a separate limit, but is tracked as the number of DML statements issued.
getLimitSavepointRollbacks Integer This method is deprecated. Returns the same value as getLimitDMLStatements. The number of Rollback methods is no longer a separate limit, but is tracked as the number of DML statements issued.
getSavepoints Integer This method is deprecated. Returns the same value as getDMLStatements. The number of setSavepoint methods is no longer a separate limit, but is tracked as the number of DML statements issued.
getLimitSavepoints Integer This method is deprecated. Returns the same value as getLimitDMLStatements. The number of setSavepoint methods is no longer a separate limit, but is tracked as the number of DML statements issued.
getScriptStatements Integer Returns the number of Apex statements that have executed.
getLimitScriptStatements Integer Returns the total number of Apex statements that can execute.
getSoslQueries Integer Returns the number of SOSL queries that have been issued.
getLimitSoslQueries Integer Returns the total number of SOSL queries that can be issued.
© Copyright 2000–2013 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.