Salesforce is a multi-tenant platform. This means your code runs in a shared environment where resources like database processing, memory, and CPU time are shared with thousands of other customers. To prevent poorly written code from monopolizing these resources, Salesforce enforces strict execution boundaries known as Governor Limits. Understanding how to work within these boundaries is the difference between a Junior developer and a Senior Architect.
Core Execution Limits You Must Master
Salesforce has two main categories of limits: synchronous and asynchronous. Synchronous limits are enforced per-transaction, while asynchronous jobs (Queueable, Batch, Scheduled) have higher allocations.
| Limit Name | Synchronous Limit | Asynchronous Limit | Architectural Strategy |
|---|---|---|---|
| Total SOQL Queries | 100 | 200 | Bulkify SOQL; query outside loops; leverage maps. |
| Total DML Statements | 150 | 150 | Consolidate updates; perform single operations on lists. |
| Maximum CPU Time | 10,000 ms | 60,000 ms | Avoid nested loops; optimize maps; move logic to async. |
| Maximum Heap Size | 6 MB | 12 MB | Use SOQL for loops; nullify heavy variables; select only needed fields. |
Total SOQL Queries
100
200
Total DML Statements
150
150
Maximum CPU Time
10,000 ms
60,000 ms
Maximum Heap Size
6 MB
12 MB
Bulkification Best Practices: Writing Scale-Safe Apex
Bulkification is the design pattern of ensuring your Apex code can handle multiple records efficiently. Never write SOQL or DML inside for loops. Doing so is a fast track to System.LimitException errors.
Advanced CPU Time & Heap Optimization
In Large Data Volume (LDV) environments, even bulkified code can hit CPU and Heap limits. When querying massive sets of data, standard collections load all records into memory, which bloats the heap. Use SOQL For Loops instead, which process records in batches of 200:
Architect Tip
When dealing with heavy payloads, always set unused variables to null before performing next-stage operations, helping the garbage collector free up heap memory.
Designing Programmatic Governor Limit Bypasses
In complex enterprise systems, recursive triggers or deep execution chains can consume excessive CPU time and query limits. Architects design bypass patterns that prevent execution loops: