UTIL_Limits
Class · Group: Utilities
Learn it: Utilities guide
global inherited sharing class UTIL_LimitsFluent 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
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.
| Group | Methods | Worked example |
|---|---|---|
| Queries, searches and cursors | aggregateQueries apexCursorRows apexCursors apexPaginationCursorRows apexPaginationCursors fetchCallsOnApexCursor soqlQueries soqlQueryLocatorRows soqlQueryRows soslQueries | UTIL_Limits |
| Saves and published events | dmlRows dmlStatements publishImmediateDml | UTIL_Limits |
| Callouts, email and push notifications | callouts emailInvocations mobilePushApexCalls | UTIL_Limits |
| Background jobs | futureCalls queueableJobs | UTIL_Limits |
| CPU time and memory | cpuTime heapSize | UTIL_Limits |
| Every limit at once | snapshot toDebugString | UTIL_Limits |
Methods
| Method | Description |
|---|---|
| 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
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
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
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
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
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
global static UTIL_Limits.LimitCheck callouts()Returns a LimitCheck for HTTP callouts.
Returns UTIL_Limits.LimitCheck — LimitCheck scoped to callouts
cpuTime
global static UTIL_Limits.LimitCheck cpuTime()Returns a LimitCheck for CPU time (milliseconds).
Returns UTIL_Limits.LimitCheck — LimitCheck scoped to CPU time
dmlRows
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
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
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
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
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
global static UTIL_Limits.LimitCheck heapSize()Returns a LimitCheck for heap size (bytes).
Returns UTIL_Limits.LimitCheck — LimitCheck scoped to heap size
mobilePushApexCalls
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
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
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
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
List<UTIL_Limits.LimitCheck> allLimits = UTIL_Limits.snapshot();soqlQueries
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
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
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
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
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
String limitsDebug = UTIL_Limits.toDebugString();Inner Classes
| Class | Description |
|---|---|
| LimitCheck | Fluent limit inspector scoped to a single governor limit type. |