Skip to content

UTIL_Limits ​

Class · Group: Utilities

Learn it: Utilities guide

apex
global inherited sharing class UTIL_Limits

Fluent interface for inspecting Salesforce governor limits. Provides named factory methods per limit type for IDE discoverability and a LimitCheck builder for threshold and exhaustion checks.

Example

apex
UTIL_Limits.callouts().isExhausted();
UTIL_Limits.soqlQueries().isNearLimit(0.8);
UTIL_Limits.cpuTime().remaining();

Methods by task ​

Find a method by what you want to do. A group links to a worked example when a guide has one. Every method is described in the full list below.

GroupMethodsWorked example
Queries, searches and cursorsaggregateQueries apexCursorRows apexCursors apexPaginationCursorRows apexPaginationCursors fetchCallsOnApexCursor soqlQueries soqlQueryLocatorRows soqlQueryRows soslQueriesUTIL_Limits
Saves and published eventsdmlRows dmlStatements publishImmediateDmlUTIL_Limits
Callouts, email and push notificationscallouts emailInvocations mobilePushApexCallsUTIL_Limits
Background jobsfutureCalls queueableJobsUTIL_Limits
CPU time and memorycpuTime heapSizeUTIL_Limits
Every limit at oncesnapshot toDebugStringUTIL_Limits

Methods ​

MethodDescription
global static UTIL_Limits.LimitCheck aggregateQueries()Tracks the child subqueries run inside SOQL queries in this transaction, which the platform calls aggregate queries.
global static UTIL_Limits.LimitCheck apexCursorRows()Tracks the rows read through Apex cursors, as the platform reports them.
global static UTIL_Limits.LimitCheck apexCursors()Returns a LimitCheck for Apex cursors created.
global static UTIL_Limits.LimitCheck apexPaginationCursorRows()Tracks the rows read through Apex pagination cursors (the cursor kind built for paging a list on screen), as the platform reports them.
global static UTIL_Limits.LimitCheck apexPaginationCursors()Returns a LimitCheck for Apex pagination cursors created.
global static UTIL_Limits.LimitCheck callouts()Returns a LimitCheck for HTTP callouts.
global static UTIL_Limits.LimitCheck cpuTime()Returns a LimitCheck for CPU time (milliseconds).
global static UTIL_Limits.LimitCheck dmlRows()Tracks the records written in this transaction by insert, update, upsert, delete and undelete, added up across all statements.
global static UTIL_Limits.LimitCheck dmlStatements()Tracks the database write statements issued in this transaction.
global static UTIL_Limits.LimitCheck emailInvocations()Tracks the calls that send email from Apex in this transaction.
global static UTIL_Limits.LimitCheck fetchCallsOnApexCursor()Returns a LimitCheck for fetch calls made on Apex cursors.
global static UTIL_Limits.LimitCheck futureCalls()Tracks the future methods (code marked to run later, in the background) that this transaction has asked the platform to run.
global static UTIL_Limits.LimitCheck heapSize()Returns a LimitCheck for heap size (bytes).
global static UTIL_Limits.LimitCheck mobilePushApexCalls()Tracks the Apex calls that send mobile push notifications in this transaction.
global static UTIL_Limits.LimitCheck publishImmediateDml()Returns a LimitCheck for publish immediate DML operations.
global static UTIL_Limits.LimitCheck queueableJobs()Tracks the Queueable jobs (background jobs) this transaction has added to the queue.
global static List<UTIL_Limits.LimitCheck> snapshot()Returns a LimitCheck for every governor limit type.
global static UTIL_Limits.LimitCheck soqlQueries()Tracks the SOQL queries issued in this transaction.
global static UTIL_Limits.LimitCheck soqlQueryLocatorRows()Tracks the records returned through query locators in this transaction.
global static UTIL_Limits.LimitCheck soqlQueryRows()Tracks the records returned by SOQL queries in this transaction, added up across all queries.
global static UTIL_Limits.LimitCheck soslQueries()Tracks the SOSL searches issued in this transaction.
global static String toDebugString()Returns a human-readable summary of all governor limits in the format "Label: used of maximum".

aggregateQueries ​

apex
global static UTIL_Limits.LimitCheck aggregateQueries()

Tracks the child subqueries run inside SOQL queries in this transaction, which the platform calls aggregate queries. Each parent-to-child subquery counts once, against a limit separate from the SOQL query limit; COUNT and GROUP BY queries are not what it counts.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to aggregate queries

apexCursorRows ​

apex
global static UTIL_Limits.LimitCheck apexCursorRows()

Tracks the rows read through Apex cursors, as the platform reports them. To track how many cursors were created, use apexCursors.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to Apex cursor rows

apexCursors ​

apex
global static UTIL_Limits.LimitCheck apexCursors()

Returns a LimitCheck for Apex cursors created. The platform counts cursor creation over a trailing 24-hour period, unlike the transaction-scoped limits in this class.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to Apex cursors

apexPaginationCursorRows ​

apex
global static UTIL_Limits.LimitCheck apexPaginationCursorRows()

Tracks the rows read through Apex pagination cursors (the cursor kind built for paging a list on screen), as the platform reports them. To track how many were created, use apexPaginationCursors.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to Apex pagination cursor rows

apexPaginationCursors ​

apex
global static UTIL_Limits.LimitCheck apexPaginationCursors()

Returns a LimitCheck for Apex pagination cursors created. The platform counts cursor creation over a trailing 24-hour period, unlike the transaction-scoped limits in this class.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to Apex pagination cursors

callouts ​

apex
global static UTIL_Limits.LimitCheck callouts()

Returns a LimitCheck for HTTP callouts.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to callouts

cpuTime ​

apex
global static UTIL_Limits.LimitCheck cpuTime()

Returns a LimitCheck for CPU time (milliseconds).

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to CPU time

dmlRows ​

apex
global static UTIL_Limits.LimitCheck dmlRows()

Tracks the records written in this transaction by insert, update, upsert, delete and undelete, added up across all statements. Check it before a large save to avoid going over the limit.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to DML rows

dmlStatements ​

apex
global static UTIL_Limits.LimitCheck dmlStatements()

Tracks the database write statements issued in this transaction. One statement that saves 200 records counts once.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to DML statements

emailInvocations ​

apex
global static UTIL_Limits.LimitCheck emailInvocations()

Tracks the calls that send email from Apex in this transaction. One call that sends several messages counts once.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to email invocations

fetchCallsOnApexCursor ​

apex
global static UTIL_Limits.LimitCheck fetchCallsOnApexCursor()

Returns a LimitCheck for fetch calls made on Apex cursors.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to Apex cursor fetch calls

futureCalls ​

apex
global static UTIL_Limits.LimitCheck futureCalls()

Tracks the future methods (code marked to run later, in the background) that this transaction has asked the platform to run.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to future calls

heapSize ​

apex
global static UTIL_Limits.LimitCheck heapSize()

Returns a LimitCheck for heap size (bytes).

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to heap size

mobilePushApexCalls ​

apex
global static UTIL_Limits.LimitCheck mobilePushApexCalls()

Tracks the Apex calls that send mobile push notifications in this transaction. One call that reaches many devices counts once.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to mobile push Apex calls

publishImmediateDml ​

apex
global static UTIL_Limits.LimitCheck publishImmediateDml()

Returns a LimitCheck for publish immediate DML operations.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to publish immediate DML

queueableJobs ​

apex
global static UTIL_Limits.LimitCheck queueableJobs()

Tracks the Queueable jobs (background jobs) this transaction has added to the queue. Check isExhausted before you add another one.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to queueable jobs

snapshot ​

apex
global static List<UTIL_Limits.LimitCheck> snapshot()

Returns a LimitCheck for every governor limit type.

Returns UTIL_Limits.LimitCheck — List of LimitCheck instances, one per limit type

Example

apex
List<UTIL_Limits.LimitCheck> allLimits = UTIL_Limits.snapshot();

soqlQueries ​

apex
global static UTIL_Limits.LimitCheck soqlQueries()

Tracks the SOQL queries issued in this transaction. A query counts once, however many records it returns; use soqlQueryRows to track the records.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to SOQL queries

soqlQueryLocatorRows ​

apex
global static UTIL_Limits.LimitCheck soqlQueryLocatorRows()

Tracks the records returned through query locators in this transaction. A query locator is the query form that batch jobs and paged lists use to read large sets of records.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to SOQL query locator rows

soqlQueryRows ​

apex
global static UTIL_Limits.LimitCheck soqlQueryRows()

Tracks the records returned by SOQL queries in this transaction, added up across all queries.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to SOQL query rows

soslQueries ​

apex
global static UTIL_Limits.LimitCheck soslQueries()

Tracks the SOSL searches issued in this transaction. A SOSL search is a text search across several objects at once.

Returns UTIL_Limits.LimitCheck — LimitCheck scoped to SOSL queries

toDebugString ​

apex
global static String toDebugString()

Returns a human-readable summary of all governor limits in the format "Label: used of maximum".

Returns String — Multi-line string with one line per limit type

Example

apex
String limitsDebug = UTIL_Limits.toDebugString();

Inner Classes ​

ClassDescription
LimitCheckFluent limit inspector scoped to a single governor limit type.