A data type is like a specialized container or box that can only hold specific kinds of values. Just as you wouldn’t put a basketball in a shoebox, different types of data need different types of containers.
Master Salesforce Apex Data Types with Interactive Visualizations
Understanding data types through visual containers and interactive examples
A data type is like a specialized container or box that can only hold specific kinds of values. Just as you wouldn’t put a basketball in a shoebox, different types of data need different types of containers.
Each data type uses different amounts of memory – like different sized storage containers
Small items go in small boxes, large items need big boxes. You can’t fit a refrigerator in an envelope!
Kitchen is for cooking, bedroom for sleeping, bathroom for hygiene. Each room has a specific purpose!
Screwdriver for screws, hammer for nails, wrench for bolts. Right tool for the right job!
Fundamental building blocks of Apex programming with detailed specifications and interactive examples
Salesforce Objects representing records in the database with comprehensive field structures
Powerful data structures for handling multiple values with different behaviors and use cases
| Operation | List | Set | Map |
|---|---|---|---|
| Add Element | O(1) | O(1) | O(1) |
| Search/Contains | O(n) | O(1) | O(1) |
| Remove Element | O(n) | O(1) | O(1) |
| Access by Index | O(1) | N/A | N/A |
Comprehensive comparison tables and expert recommendations for choosing the right data types
| Data Type | Memory Size | Range/Capacity | Primary Use Cases | Performance | Example |
|---|---|---|---|---|---|
| Integer | 4 bytes | -2³¹ to 2³¹-1 | Counters, loop indices, quantities | ⚡ Fastest | Integer count = 100; |
| Long | 8 bytes | -2⁶³ to 2⁶³-1 | Timestamps, large numbers | ⚡ Very Fast | Long timestamp = System.currentTimeMillis(); |
| Double | 8 bytes | ±1.7E±308 (15-17 digits) | Scientific calculations, math | ⚡ Fast | Double pi = Math.PI; |
| Decimal | Variable | 28-29 significant digits | Currency, financial calculations | 🐌 Slower but precise | Decimal price = 199.99; |
| String | 2 bytes/char | ~6M characters | Text, names, descriptions | 🐌 Memory intensive | String name = ‘John Doe’; |
| Boolean | 1 byte | true or false | Flags, conditional logic | ⚡ Fastest | Boolean isActive = true; |
| ID | 15-18 bytes | Salesforce records only | Record references, SOQL | ⚡ Fast | ID accountId = ‘001D000001234567’; |
| Date | 8 bytes | 1700-4000 (approx) | Birthdays, due dates | ⚡ Fast | Date birthday = Date.newInstance(1990, 5, 15); |
| DateTime | 16 bytes | Date + Time + Timezone | Timestamps, logging, scheduling | ⚡ Fast | DateTime now = DateTime.now(); |
| Blob | Variable | 6MB (heap limit) | Binary data, files, images | 🐌 Memory intensive | Blob data = Blob.valueOf(‘Hello’); |
| List<T> | Variable | Limited by heap | Ordered data, indexed access | ⚡ Fast access, 🐌 search | List<String> items = new List<String>(); |
| Set<T> | Variable | Limited by heap | Unique values, fast lookup | ⚡ Very fast lookup | Set<String> unique = new Set<String>(); |
| Map<K,V> | Variable | Limited by heap | Key-value relationships | ⚡ Very fast lookup | Map<String, String> data = new Map<String, String>(); |